title: Programmatically change text config files in Linux with minimal effort
body: <p>I am looking for a tool that would ease the modification of text configuration files for tasks like:</p>
  
  <ul>
  <li>Set <code>ForwardAgent yes</code> on /etc/ssh/ssh_config</li>
  <li>Append <code>HGUSER</code> to <code>AcceptEnv</code> in /etc/ssh/sshd_config (that's more complex as it does accept several params, if yours is not alread there it should add it)</li>
  </ul>
  
  <p>Most important: </p>
  
  <ul>
  <li>running it several times should have no side effects.</li>
  <li>if something looks weird, it should complain (for example if you find the same line several times in a file, or if the expected syntax does not match).</li>
  </ul>
  
  <p>Is there any linux tool that can easily be used to automate things like this?</p>
  
  <p>The whole point is to be able to write these config patches somewhere so you can deploy them on several machines or on a new machine when needed.</p>