This is an old revision of the document!


grep -Z -R -l -E 'searchpattern' . | xargs -0 sed -i 's/searchpattern/replacestring/g'
  • :!: remember to escape parenthesis when using sed
  • this example finds all occurences of 'oldhostname' where it is not followed by a period, and replaces it with 'newhostname'
grep -Z -R -l -E 'oldhostname[^\.]' . | xargs -0 sed -i 's/oldhostname\([^\.]\)/newhostname\1/g'
  • docs/bash/search_and_replace_in_files.1243621070.txt.gz
  • Last modified: 2009/05/29 12:17
  • by billh