How to display the output of a file without the blank lines

root's picture

[font=Verdana]There are many ways to achieve this and they should work on all unixes:[/font]

[font=Verdana]With grep:[/font]
gz@shell~$ grep -v '^[[:space:]]*$'
gz@shell~$ grep -v ‘^$’ file
gz@shell~$ grep ‘.’ file

[font=Verdana]With awk:[/font]
gz@shell~$ awk '{ if (length($0) > 0){ print $0 }}'
gz@shell~$ awk NF file
gz@shell~$ awk ‘/./’ file

[font=Verdana]With sed:[/font]
gz@shell~$ sed ‘/^$/d’ file
gz@shell~$ sed -n ‘/^$/!p’ file

[font=Verdana]Know more? Leave a message :)[/font]

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root