Re: [SLUG] Global Search and Replace

From: ronan (ronan@tampabay.rr.com)
Date: Wed Jan 10 2007 - 05:54:18 EST


blee2@tampabay.rr.com wrote:
> Thus Paul M Foster hast written on Thu, Jan 04, 2007 at 04:16:54PM -0500, and, according to prophecy, it shall come to pass that:
>
>> Anyone know of a nifty tool which will do a global search and replace of
>> text inside a bunch of files, all at once?
>>
>
>
> I use sed. The syntax is the same as the perl example:
>
> sed -e 's/string1/replacement/g' infile
>
>
> You'll probably want to run this sed with a for loop:
>
> for i in *.txt
> do
> sed -e 's/worker/slave/g' $i > $i.new
> done
>

I use sed for this as well, but instead of the "$i > $i.new" (assuming
that you want in-place replacement), use the -i option:

sed -i 's/string1/replacement/g' infile

--ronan

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:31:09 EDT