<p>Is there a way to add text to an arbitrary place in a text file?</p>
<p>&lt;pseudocode&gt;<br>
NewAddition=&quot;this important directive. &quot;</p>
<p>Open config.config<br>
Add new line above &quot;# this marker text in config.config&quot;<br>
Insert $NewAddition in blank line created above.<br>
Save config.config<br>
Close config.config<br>
&lt;\pseudocode&gt;</p>
<p>I am automating adding servers to nagios monitoring. I already have the part that creates the new server.cfg file. This was a fairly simple bash script. I am planning to write it in python instead, so i can let the administrator choose the services to enable in a series of if statements, rather than having to hand-edit the resultant file.</p>

<p> I need my script to add this filename to the main nagios.cfg list of read files, but it isn&#39;t going to work to do it as a straightforward append...<br>
Unless I can append it to a serverlist file and insert that file into nagios.cfg at the proper position...<br>
</p>