Thursday, March 6, 2008

remove blankline awk

Many times of output of some packages contain lot of blank lines. You can remove those blank line using awk as follows:

Assume that /tmp/test is the file containing blank lines

cat /tmp/test | awk '$0!~/^$/ {print $0}' > /tmp/test1

This script is to exclude blank line ^ represent beginning of a line, $ represents end of a line, therefore ^$ stands for a line without any contents. ! stands for not.

It could be done by grep in the similar way. grep -v "^$" filename > newfilename
-v stands for "not"

No comments: