<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>So I have a copy of sudoers in my home directory for purposes of messing it up (or not).<br></div>
<div>&nbsp;</div>
<div>I want to locate the line<br></div>
<div>&nbsp;</div>
<div>Defaults &nbsp; &nbsp;Env_reset [unknown number of spaces in middle, zero to unknown number of spaces at end of line]<br></div>
<div>&nbsp;</div>
<div>and after that line insert a line that says<br></div>
<div>&nbsp;</div>
<div>Defaults &nbsp; &nbsp;editor=/bin/nano [four spaces in middle, no spaces at end of line]<br></div>
<div>&nbsp;</div>
<div>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.<br></div>
<div>&nbsp;</div>
<div>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.)<br></div>
<div>&nbsp;</div>
<div>sed -i.bak 's:(^Defaults\s*Env_reset\s*)$:$1\nDefaults &nbsp; &nbsp;editor=/bin/nano:' ./sudoers<br></div>
</body>
</html>