[colug-432] Regex
Steve VanSlyck
s.vanslyck at postpro.net
Sat May 16 22:03:08 EDT 2015
So I have a copy of sudoers in my home directory for purposes of messing
it up (or not).
I want to locate the line
Defaults Env_reset [unknown number of spaces in middle, zero to unknown
number of spaces at end of line]
and after that line insert a line that says
Defaults editor=/bin/nano [four spaces in middle, no spaces at
end of line]
I think $1 copies the prior group, which is identified by parens. So
what happens is that sed finds the original line, then replaces that
line with the original line plus a newline plus an additional line to
set the editor.
Does this look like a reasonably good sed/RegEx line to do that? (Point
was noted about not using i.bak yet, but this is not working on the
actual sudoers file.)
sed -i.bak 's:(^Defaults\s*Env_reset\s*)$:$1\nDefaults
editor=/bin/nano:' ./sudoers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20150516/1964e91d/attachment.html
More information about the colug-432
mailing list