<!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> </div>
<div>I want to locate the line<br></div>
<div> </div>
<div>Defaults Env_reset [unknown number of spaces in middle, zero to unknown number of spaces at end of line]<br></div>
<div> </div>
<div>and after that line insert a line that says<br></div>
<div> </div>
<div>Defaults editor=/bin/nano [four spaces in middle, no spaces at end of line]<br></div>
<div> </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> </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> </div>
<div>sed -i.bak 's:(^Defaults\s*Env_reset\s*)$:$1\nDefaults editor=/bin/nano:' ./sudoers<br></div>
</body>
</html>