[CentOS] find cont'd 3
haldir.junk at gmail.com
Fri Oct 10 14:19:21 UTC 2008
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
Hmm, why not ditch find entirely, and just use grep? Something like:
grep -Ilr "$STR" * > $TFIL
for fil in $( cat $TFIL); do
sed -i "s/$STR/$NEW/g" $fil
Man grep says: "-I Process a binary file as if it did not contain
matching data". Also -l gives you the filename and relative path.
If $STR contains "/"s then you could use # instead.
sed -i "s#$STR#$NEW#g" $fil
I dont know how much the searched for string would change, but you
could test if it contained "/" and then use sed with "#" instead.
Also you might want to use "sed -ibak ..." instead since this will
backup the unchanged file to filename.bak, should your substitution go
awry. The letters after "i" specify the extension you want to use.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the CentOS