Tag Archives: linux tips

Linux Tips ( grep the text without hashes and blank lines )

In our second post of linux tips i would like to share a very simple example in which i will use grep tool to remove all the hashes and blank lines from a file.

In our example we will use file1.txt with the following content

linux-11oz:/test # cat file.txt 
#The file with hashes
###
####
##

This is a test file

With lots of spaces


and few lines with


####hashes
###

So lets remove the hashes and blank lines with single grep command

We can use the following trick

linux-11oz:/test # grep . file.txt | grep -v "#"
This is a test file
With lots of spaces
and few lines with

The “.” will remove the blank lines and  “-v” will invert the match of #

Thats how simple it is. If you know a better way of doing it , Please send me an email or comment.

Email: learning@itpings.com

Thanks

Salman A. Francis