Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] batch text editting

sed is you friend

lets assum there DNS files and you need to update the serial numbers so
each file has something like

		2000057100   ; Serial
to update them all to todays serial
I'm going to assume they've all been changed at least this year to make
the regex simpler


cd /var/named
for i in db.*;
sed 's/2000[0-9][0-9][0-9][0-9][0-9][0-9][:space:]*;[:space:]*Serial/2000102100 ;Serial/' < $i > $i.tmp
&& mv $i.tmp $i

make sure you back up befor you try anything :)

On Sat, Oct 21, 2000 at 02:34:06AM -0400, Daniel Freedman wrote:
> Hi,
> I'm looking to do some batch text editing by applying the changes I make
> to one file to many other similar (although not identical) files.  The
> text portions I'm changing in the first file, however, ARE in fact
> identical in the other files.
> I was thinking of doing a context diff and then a patch, but I don't think
> I can easily edit the context diff such that, upon patching, it will only
> patch certain areas (I know the patch is wise to its context, it's just
> that I don't think i can easily alter the patch itself before applying,
> because its embedded line numbers would have to be changed to account
> for my edits in the patch).
> I also tried to do a diff -e (to produce some patchfile 'p' to feed to
> ed), then hand-edit 'p', then invoke: 
>          (cat p; echo '%p') | ed - orig > new
> This should work better, I think, since it reverse lists the changes to
> somewhat avoid the line numbering problem.  It is, in fact, working in
> some cases, but when the hand-editing of the patchfile is more involved,
> it's not very graceful.  I list an example below.
> Am I missing something here, please?  Is there a better way to do this
> (I'm sure there is)?
> Thanks for any and all suggestions...  I really appreciate your help.
> Take care,
> Daniel
> -- 
> SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
> More Info: http://slug.org.au/lists/listinfo/slug


The difference between a good man and a bad one is the 
choice of cause - William James