Pages

11/21/2011

In-place Replace by Ruby

The following code will replace "searchword" from all *.txt files with word "newword".
The original files will be changed, and backup file will have .bak extension.
ruby -pi.bak -e "gsub(/searchword/,"newword")" *.txt
sed command:
sed -i "s/searchword/newword" filename
sed for multiple-file (using find command)
find /path -n "*.txt" -type f -exec sed -i "s/searchword/newword" {} \;

No comments:

Post a Comment