Tip #153 In-place multiple-file search and replace
Regular expression search and replace on files "in-place" can be done with perl:perl -pi -e 's/foobar/fooBar/g' file1 file2 file3
For example, here's how to change a package name for an entire Java source tree from net.widgets.* to com.widgets.*:
mv src/net src/com
find src -name '*.java' -print0 | xargs -0 perl -pi -e 's/^package net.widgets./package com.widgets./'
To have perl make backups of the original files first, follow the -i option with a suffix to append.
- TAGS:
alias aptitude at awk bash bc cal cat cd colrm comm cp csh curl cut date dd df dialog diff dirname dpkg du fc find fuser grep gs gzip history iconv kill ksh last less ln ls lsof lynx m4 md5sum mkdir mkfifo mkisofs mv mysql nc netstat openssl OSX perl ping popd ps pushd python read redirection rm scp screen sed sort ssh stat sudo svn tail tar tee test top tr uniq vim wc wget xargs