Advertisement

find and replace recursively within a directory

Started by September 17, 2005 02:59 PM
2 comments, last by clayasaurus 19 years ago
is there a program to find and replace text recursively of all files within a directory ? is there an awk script to do such a thing? Thanks. ~ Clay
This should work:

for f in dir/*
do
cat $f |sed 's/old/new/g' > $f
done

Replace "dir" "old" and "new" with your own values.
You can type that right in a terminal or put it into a shell script.
Advertisement
Quote: Original post by Anonymous Poster
cat $f |sed 's/old/new/g' > $f


Rather use
sed -i 's/old/new/g' $f

-i for in place.
Thanks. This script has made my life a bit easier : )

This topic is closed to new replies.

Advertisement