> >I need to update a config file automatically. I currently update this
> >file manually.
> >Does anyone have a script which will update a file? Is sed, awk, or
> >some other tool the best way to go? Opinions?
> >Specifically, I need to update iPlanet's obj.conf and mime.types
> >files. The existing files do not need to be updated,
> >I just need to add objects, etc.
> >i.e.: obj.conf
> ># shell script adds these lines
> >newly added line3
> >newly added line 4
> >line 5 (was line 3 before update)
> >Thank You, and God Bless America!!!
Yes, God Bless America! And please don't top-post!
Well, without having any idea what line2 and/or line3 looks like,
the only help you can get is general solutions. As long as you
know regular expressions well, and vi/ex commands, try this model,
ex - filename << EOF
I designed many a here document with different editing-commands
using this technique. In fact I wrote a script called exauto
(now too big to post here) that alows you to store these ex editing
commands in a separate file, so that you could type,
exauto -f excmds filename
and filename would be edited with commands from excmds file. The
exauto script built a * here document, inserted contents of
file called excmds in place of <editing-commands> and executed it.
exauto was kinda a poor man's sed, but has proven advantagous over
the years for sed-like editing that needed to be automated over
really REALLY large amount of files.
An explanation of the here document contents:
w! %.orig -- saves copy of original filename with .orig extension.
<editing-commands> -- are your ex editing commands.
q -- will exit if no changes were made, effectively skips the wq
wq -- if changes were made, the q fails, so this wq saves the changes
The editing-commands usually require you to position yourself, then
type a, add the lines to insert, then close with a single .
If you need help on the editing-commands, provide an example of what
line2 and line3 look like. You need to tell us plainly why line2/3
was chosen. Why did you insert between line2 & line3 in your example?
Is it based upon line number, or based upon a regular expression?
The advantage I've found in using this technique is that I don't
always have to be an expert at sed. I can use ex, which most vi
folks know better than they think.
I also like the positioning of the 'cursor' that ex provides. sed
is one pass only, but ex commands will 'move' the cursor around
using the same thought processes that your vi brain cells follow.