[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: OT: Sed/Perl script tp comment out specifc line



On Fri, 31 Aug 2001, Chuck wrote:

>
> I have about 200 remote servers that run a custom application each with
> a tailored config file (ie no two are the same). I need to comment out 2
> lines that are the same in every file for all 200 servers. What is the
> easiest way to do this? I currently use rsh to manage these servers so I
> wanted to create a script, either in perl or sed, that can modify the
> file, distribute this script to each host and execute it there.
>
> How would you guys go about this?
>
> Thanks,
> CC
>
>
It is hard to say what tool would work best without knowing more, but
sed, or ask would do this.  Or if you want to remove the lines, instead
of commenting them out, you could feed the file through grep twice,
using the -v option.  (Or once, using | to joint the two lines to
match.)  If you are not comfortable with regular expressions, try
something like this to remove the two lines:

#!/bin/bash
#
CONFIG=<config file>
STRING1="<first string to match>"
STRING2="<second string to match>"

grep -v $STRING1 $CONFIG | grep -v $STRING2 > /tmp/tmpfile
mv $CONFIG $CONFIG.old
mv /tmp/tmpfile $CONFIG

Note, it could be done using grep only once, but this is easy to
understand.  the first grep reads the config file, and passes everything
that doesn't match the first string to the second grep.  The second grep
write everything that doesn't match the second string to /tmp/tmpfile.
then we rename the origional config file, and replace it with the file
from /tmp/tmpfile.

Mikkel
 --

    Do not meddle in the affairs of dragons,
 for you are crunchy and taste good with ketchup.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]