john hedge wrote:

> My challenge is to search a directory of text files for a string which I
> want to replace wherever it occurs with a new string and save the file with
> the changes in the same original file name.

In the past I've used something like:


for file in `find -type f -name 'whatever'`
do
        (echo '1,$s/oldstring/newstring/g' && echo 'wq') | ex $file
done


.. quite successfully for this purpose. It basically just drives 'ex' to do
precisely what you'd do if you were doing it manually.

Test it somewhere with a copy of your files first though!

regards
Terry

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to