sed -e 's/#.*//' -e 's/[ ^I]*$//' -e '/^$/ d'
...so I don't have to think of it again.
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’
Yo don’t need ‘s’ command, just use ‘d’ : sed -e ‘/^#/ d’ -e ‘/^ *$/ d’
Thanks!
I came up with: sed -e ‘s/\s*#.*//’ -e ‘/^\s*$/ d’
You need ‘s’ if you want the comment to be removed, if there is content before it in the same line. This solution also covers lines beginning with spaces before the comment, like the the op’s does.
Name (required)
Email (required)
Website
Trackbacks are disabled.
January 17th, 2009 - 21:30
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’
December 2nd, 2012 - 05:27
Yo don’t need ‘s’ command, just use ‘d’ : sed -e ‘/^#/ d’ -e ‘/^ *$/ d’
December 13th, 2012 - 20:35
Thanks!
January 31st, 2013 - 21:39
I came up with:
sed -e ‘s/\s*#.*//’ -e ‘/^\s*$/ d’
You need ‘s’ if you want the comment to be removed, if there is content before it in the same line.
This solution also covers lines beginning with spaces before the comment, like the the op’s does.