Thursday, April 7, 2011

Linux Tips & Tricks

Removing commented lines '#' from a file
grep -v '^#' squid.conf > squid.conf.new

to remove empty lines from a text file. I've been using sed with
sed '/^ *$/d' squid.conf.new > squid.conf.nospace

Do the same thing with sed in one line
sed '/^#/d' squid.conf.default | sed /^$/d > squid.conf.new

Or
sed -e '/^\(#\|$\)/ d' squid.conf.default > squid.conf.new

Remove comments and blank lines from a file
egrep -v '^(#|$)' squid.conf.default > squid.conf.new

Or
grep '^[^#]' squid.conf > squid.conf.new

No comments:

Post a Comment