Friday, January 18, 2008

Find and Replace words from a file

Please use the following code to update files with perl.

1)perl -pi -e 's/wordToFind/replaceWithThisWord/g' *.fileExtension


eg:
create a test.txt file with contents niyas
Then execute
perl -pi -e 's/niyas/pratheesh/g' test.txt

Also you can take the backup of the original file using the command

2)perl -pi.bak -e 's/niyas/pratheesh/g' test.txt


3)replace current_text final_text --filename

See the change :)

No comments: