11 November 2007

Bulk search and replace using sed

This little snippet replaces occurrences of oldString with newString in all files named *.txt in the current directory and below, keeping a backup of the original files.

for i in $(find . -name "*.txt"); do sed 's/oldString/newString/g' $i > $i-tmp; mv $i $i-backup; mv $i-tmp $i; done