Re: regexp---remove comments---simplification
On Fri, Feb 21, 2003 at 07:18:48AM -0600, Gary Turner wrote:
> Not an earth-shattering problem. I try to remove all those comments
> from various config files before emailing them to wherever. I currently
> chain some greps
>
> grep -v '^\ *#' some.conf | grep -v '^\ $' > condensed.file
>
> How would you combine these regexp's to remove a commented line (even if
> indented) and a blank line? My various permutations and combinations
> have resulted in errors.
You'll want something like this:
grep -v '^\( *#\| $\)' some.conf > condensed.file
or:
egrep -v '^( *#| $)' some.conf > condensed.file
The spaces don't need to be escaped in either case; (|) need to be
escaped for basic grep but not for egrep.
Cheers,
--
Colin Watson [cjwatson@flatline.org.uk]
Reply to: