Table of Contents

Search and Replace in Files

grep -Z -R -l -E 'searchpattern' . | xargs -0 sed -i 's/searchpattern/replacestring/g'

Advanced Example

grep -Z -R -l -E 'oldhostname[^\.]' . | xargs -0 sed -i 's/oldhostname\([^\.]\)/newhostname\1/g'

FreeBSD 5 Example

grep --null -R -l -E 'oldhostname[^\.]' . | xargs -0 -t sed -i '.sed' 's/newhostname\([^\.]\)/xdev\1/g'

See Also