krono pomoz' blog, by Ivan Savcic

22Nov/074

Remove comments and empty lines sed one-liner

sed -e 's/#.*//' -e 's/[ ^I]*$//' -e '/^$/ d'

...so I don't have to think of it again.

Comments (4) Trackbacks (0)
  1. Thanks for the one-liner. This is exactly the thing I was looking for to help parse a hosts file.

    sed -e ‘s/#.*//’ -e ‘s/[ ^I]*$//g’ -e ‘/^$/ d’ -e ‘s/127.0.0.1 //g’ -e ’1,3d’

  2. Yo don’t need ‘s’ command, just use ‘d’ : sed -e ‘/^#/ d’ -e ‘/^ *$/ d’


Leave a comment

 

Trackbacks are disabled.