Help with sed script?
Michael ODonnell
michael.odonnell at comcast.net
Tue Sep 5 15:35:01 EDT 2006
I'm trying to use sed to rewrite lines in a config file that
have a target string 'xyz' in them surrounded by whitespace
and which are NOT commented out with a hash sign and which
may or may not have leading whitespace. This expression:
sed -r -e '/^[[:space:]]*[^#].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
...mostly works:
echo 'abc xyz' | sed -r -e '/^[[:space:]]*[^#].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
REWRITTEN
echo ' abc xyz' | sed -r -e '/^[[:space:]]*[^#].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
REWRITTEN
echo '#abc xyz' | sed -r -e '/^[[:space:]]*[^#].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
#abc xyz
...but the part that's gonna make me go postal is that it seems
like *any* leading whitespace makes the entire expression match
even when it really shouldn't:
echo ' #abc xyz' | sed -r -e '/^[[:space:]]*[^#].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
REWRITTEN
I'm probably missing something obvious but at this point I
could sure use a few whacks with a clue-stick...
More information about the gnhlug-discuss
mailing list