Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] batch text editting


Thanks for the suggestion (and thanks also to Jeff's earlier one) but I'm
not sure how easy sed would work in my situation (although I did consider
it and maybe this feeling is just due to my inexperience with it as a
power tool). Maybe I should have been more specific about the types of
files I'm changing.  I have this heirarchy of maybe thirty or forty
related HTML files (all hand-written of course, so no extra crap from a
windows page formatter like dreamweaver, and therefore, presumably, easier
to batch edit on), where I'm changing all kinds of things throughout the
place in the primary root one (indentations, capitalizations, rewriting
parts, etc.). I would like all of these changes (of the standardized parts
of all the HTML files, like the navigation panels, etc.) to be propogated
to all other HTML files, but at the same time I don't want the embedded
content, title, headers, etc. to be changed (which was why a simply 'diff
-c', 'patch' wouldn't work out-of-the-box).  (I don't need help with the
command to apply the changes to lots of files (find <> -exec <> \; or by
hand), I just need help with the process of applying it to a given file.)  
I'm sure sed could work (much more easily surely for someone who's more
familiar with it than I), but isn't this type of batch editing that I'm
looking to do, not really sed's specialty?

Maybe I just don't realize the power and flexibility of some of these
tools, but I was also hoping to find something relatively straightforward
(ie not have to write huge regexp's to nail down my changes).

Thanks again and I would continue to appreciate any suggestions or
corrections of my misperceptions.

Take care,


On Sat, 21 Oct 2000, John Ferlito wrote:

> 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
> #!/bin/bash
> cd /var/named
> for i in db.*;
> do
> 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
> done
> 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
> -- 
> John
> The difference between a good man and a bad one is the 
> choice of cause - William James