Help with sed script?

Michael ODonnell michael.odonnell at comcast.net
Wed Sep 6 10:59:01 EDT 2006


>Are you sure that your new regexp does what you want?:
>
>echo 'xyz' | \
> sed -r -e '/^[[:space:]]*[^#[:space:]].*[[:space:]]+xyz[[:space:]]*/{s/^.*$/REWRITTEN/}'
>
>You specify "surrounded by whitespace" in your original description,
>but "occurs at the beginning of a line" might be reasonable too (I
>don't know what your file looks like...).


One of the config files I'll be working with is /etc/fstab
and I'll be keying on the mountpoint field i.e.  the second
whitespace-delimited token on any line that hasn't been
commented out.  So far, that RE does appear to be having the
desired results, though I'm sure many refinements are possible.

BTW, my efforts to accomodate leading whitespace are probably
a waste of time, at least when dealing with /etc/fstab.
Even though (I think) leading whitespace is technically
allowed there, various scripts (at least on our RHAT systems)
have been "enhanced" with code (like the RAID startup logic in
/etc/rc.sysinit) that dies horribly when it encounters leading
whitespace in /etc/fstab...                  >-(
 



More information about the gnhlug-discuss mailing list