How do I find and replace every occurrence of:
subdomainA.example.com
with
subdomainB.example.com
in every text file under the /home/www/
directory tree recursively?
How do I find and replace every occurrence of:
subdomainA.example.com
with
subdomainB.example.com
in every text file under the /home/www/
directory tree recursively?
For replace all occurrences in a git repository you can use:
See List files in local git repo? for other options to list all files in a repository. The
-z
options tells git to separate the file names with a zero byte, which assures thatxargs
(with the option-0
) can separate filenames, even if they contain spaces or whatnot.For anyone using silver searcher (
ag
)Since ag ignores git/hg/svn file/folders by default, this is safe to run inside a repository.
just to avoid to change also
but still
(maybe not good in the idea behind domain root)
According to this blog post:
To cut down on files to recursively
sed
through, you couldgrep
for your string instance:If you run
man grep
you'll notice you can also define an--exlude-dir="*.git"
flag if you want to omit searching through .git directories, avoiding git index issues as others have politely pointed out.Leading you to:
You can use awk to solve this as below,
hope this will help you !!!