Tuesday, October 19, 2010

Linux: Seach & Replace String in any/multiple files

Search & Replace in multiple files:
perl -n -i -e 's/originalword/newword/i; print;' *.txt
Where *.txt means all the files in the directory having extension .txt.
Search & Rrplace in single file:
a) sed -i s/originalword/newword/g filename.txt
b) replace originalword newword <original.txt >new.txt
Replace command always creates new file with new replaced string.



No comments:

Post a Comment