0

how to remove blank lines in file

In some of the files containing more than 50 lines of code, many blank line appears..... How can i remove those blank lines.....?????

grep sed command awk Add a comment
ethan
asked Feb 07 2017

Answer

0

To remove only blank lines in files, either awk or sed command could be used.

awk command helps to display the file without blank lines, whereas sed could be used to modify the source file itself...

For example:

Assume test file contains 50 lines with blank lines.

To view only:

#awk 'NF' test

To modify file:

#sed -i '/^$/d' test
Add a comment
jagannatharumugam
asked Feb 10 2017
edited Oct 05 2018
Post your Answer