SHARE
TWEET

Linux command line global search and replace

a guest Feb 26th, 2012 35 Never
  1. [filename]:[line number]:[text]
  2.        
  3. perl -p -i -e 's/oldstring/newstring/g' `grep -ril searchpattern *`
  4.        
  5. sed -i 's/foo/bar/g' *
  6.        
  7. find -name '*.html' -print -exec sed -i.bak 's/foo/bar/g' {} ;
  8.        
  9. for i in *; do
  10.   sed -i 's/foo/bar/' $i
  11. done
  12.        
  13. ruby -i.bak -pe 'sub(%r{foo}, 'bar')' *
  14. perl -pi.bak -e 's/foo/bar/' *
  15.        
  16. find -name '*.htm?' -print -exec sed -i.bak 's/foo/bar/g' {} ;
RAW Paste Data
Top