[CentOS] find cont'd 3

Fri Oct 10 17:23:26 UTC 2008
MHR <mhullrich at gmail.com>

On Fri, Oct 10, 2008 at 7:19 AM, Eric Sisolak <haldir.junk at gmail.com> wrote:
> On Wed, Oct 8, 2008 at 9:49 PM, <tony.chamberlain at lemko.com> wrote:
>>
>> Basically I want to find all files with a string (except binary)
>> and change it.  let STR be the string I am looking for.  NEW is new
>> string.
>
> Hmm, why not ditch find entirely, and just use grep?  Something like:
>
> TFIL=/usr/tmp/dummy$$.txt
>
> grep -Ilr "$STR" * > $TFIL
>
> for fil in $( cat $TFIL); do
>  sed -i "s/$STR/$NEW/g" $fil
> done
>

That should work, but unless you actually need to see the file list,
you can do this in one command:

for fil in `grep -Ilr "$STR" *`; do sed -i "s/$STR/$NEW/g" $fil; done

If you really need the file list separately, you can use `grep -Ilr
"$STR" * | tee $TFIL` to get the same effect.

Note that this will not necessarily work with specific sets of files
(as opposed to '*').

mhr