Saturday, January 14, 2012
6:58 PM

Removing blank lines from a file

Removing blank lines from a file is common requirement. Here are few simple ways we can do it.

1. Using cat and grep



The symbol ^ searches for a string that is followed from the beginning of the line. The symbol $ signifies the end of the line. Thus the combination ^$ means from begingin till the end there is nothing in the line, which would be the case in a blank line.

The same logic applies to all the examples below.

2. Using sed



3. Modifying the fine in place using sed

Please note that this will change the orginal file itself.



4. Using awk

0 comments:

Post a Comment