Want more features on Pastebin? Sign Up, it's FREE!
Guest

Linux command line global search and replace

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.38 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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' {} ;
clone this paste RAW Paste Data