<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
This worked for me:<br>
<br>
sed -e 's:^\(Defaults.*env_reset\) *$:\1\<br>
Defaults editor=/usr/bin/nano:' /etc/sudoers > tmp<br>
if [ -s tmp ]; then mv sudoers sudoers.bak; mv tmp sudoers; fi<br>
<br>
<br>
sudoers before:<br>
<br>
...<br>
Defaults env_reset<br>
Defaults mail_badpass<br>
Defaults
secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"<br>
<br>
...<br>
<br>
sudoers after:<br>
<br>
...<br>
Defaults env_reset<br>
Defaults editor=/usr/bin/nano<br>
Defaults mail_badpass<br>
Defaults
secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"<br>
<br>
...<br>
<br>
<br>
In sed use '\(' and '\)' to delimit the text you want to save from a
regular expression and \n where 1<=n<=9 to indicate the saved
text from the regular expression. Sed uses regular expressions from
the Bell Labs formulation, not Perl. The backslash at the end of
the first line indicates sed is to swallow the newline character as
a part of the replacement expression, otherwise it will complain
about a non-terminated expression.<br>
<br>
Using the '-e' option allows you to have multiple editing
expressions in a single go. I use it even when I have just one
expression to do out of habit.<br>
<br>
I don't think I have ever used the -i option. Years ago I blew away
several months of work using sed to perform an edit on a number of
source code files. Then I found out the sysadmin could not restore
my code from backup. Ever since I've been leery of doing something
that could not be restored. I guess I'm from the old school.<br>
<br>
Hope this helps.<br>
<br>
Steve<br>
<br>
<div class="moz-cite-prefix">On 05/17/2015 02:03 AM, Steve VanSlyck
wrote:<br>
</div>
<blockquote
cite="mid:1431828188.734885.270621049.3F6DCAFF@webmail.messagingengine.com"
type="cite">
<pre wrap="">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
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
colug-432 mailing list
<a class="moz-txt-link-abbreviated" href="mailto:colug-432@colug.net">colug-432@colug.net</a>
<a class="moz-txt-link-freetext" href="http://lists.colug.net/mailman/listinfo/colug-432">http://lists.colug.net/mailman/listinfo/colug-432</a>
</pre>
</blockquote>
<br>
</body>
</html>