Getting rid of extra blank lines

Some text files contain two or more blank lines together. If you need to remove the extra blank lines, use the following syntax:

$ cat -s file

Consider the following example:

$ cat multi_blanks.txt
line 1


line 2
 


line 3
     



line 4

$ cat -s multi_blanks.txt # Squeeze adjacent blank lines
line 1
      
line 2
      
line 3

line 4

We can remove all blank lines with tr, as discussed in the Translating with tr recipe in this chapter.