Linux Tip: Removing blank lines from a text file

Method 1: Using grep

$ grep -v '^$' infile.txt > outfile.txt

Method 2: Using sed

$ sed '/^$/d' infile.txt > outfile.txt

To remove blank lines from multiple files a script like the one below can be used

#!/bin/sh
files="/somefolder/*.txt"
for f in $files
do
  sed '/^$/d' $f > $f.tmp
  mv  $f.tmp $f
done