<div dir="ltr">On Wed, Oct 8, 2008 at 9:49 PM, <<a href="mailto:tony.chamberlain@lemko.com">tony.chamberlain@lemko.com</a>> wrote:<br>><br>> Basically I want to find all files with a string (except binary)<br>> and change it.  let STR be the string I am looking for.  NEW is new string.<br>
<br><br>Hmm, why not ditch find entirely, and just use grep?  Something like:<br><br>TFIL=/usr/tmp/dummy$$.txt<br><br>grep -Ilr "$STR" * > $TFIL<br><br>for fil in $( cat $TFIL); do<br> sed -i "s/$STR/$NEW/g" $fil<br>
done<br><br>Man grep says: "-I     Process a binary file as if it did not contain<br>matching data".  Also -l gives you the filename and relative path.<br><br>If $STR contains "/"s then you could use # instead.<br>
 sed -i "s#$STR#$NEW#g" $fil<br>I dont know how much the searched for string would change, but you<br>could test if it contained "/" and then use sed with "#" instead.<br>Also you might want to use "sed -ibak ..." instead since this will<br>
backup the unchanged file to filename.bak, should your substitution go<br>awry.  The letters after "i" specify the extension you want to use.<br><br>Eric Sisolak<br></div>