There are certainly more than 3 ways to do this. Typically I’ve always used sed
to do this, but here’s my method using sed
and two other methods using tr
and awk
:
sed:
sed '/^$/d' file_with_blank_lines
tr:
tr -s '\n' <file_with_blank_lines
awk:
awk '{ if ($0) print $0 }' file_with_blank_lines
If you have other favorite ways, leave a note in the comments!
If you don’t care about the order of the lines in the resulting file (or removing duplicate lines), this is another method: