How to mass Search & Replace in text files.

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Fri May 1 16:25:24 UTC 2009


On Fri, 1 May 2009, Jamon Camisso wrote:
> Lance F. Squire wrote:
> > Alex Beamish wrote:
> > > The classic tool for doing this is sed .. but you could also use perl
> > > -ie 's/Bad JS//' *.html
> > > 
> > 
> > So....
> > 
> > sed 's/Bad JS//' *html
> > 
> > Would that search recursively?
> 
> I prefer using a shell, so I'd use something like this:
> 
> for i in `grep "Bad JS" *.html -R -l`; do echo "Bad JS found in $i"; sed -i
> 's/Bad JS//' $i; done
> 
> To others on the list, what's the better way using grep/find? Seems like using
> grep recursively in this case accomplishes the same thing as grepping through
> find results.

find . -name '*.html' -print0 | xargs -0 sed -i.bak 's/Bad JS//'


-- 
   Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list