register
other register

Friday, August 03, 2007

Replacing string in multiple files without changing filenames.

#!/bin/sh

for file in /path/to/my/files/*
do
sed 's/stringA/stringB/g' $file > $file.new
mv $file.new $file
done
exit 0

Make the script executable
$ chmod u+x foo.sh

Then run it (assuming it's in the current directory)
$ ./foo.sh

For more sed examples, please have a look at the IBM articles

No comments: