views:

424

answers:

2

Using just grep and sed, how do I replace all occurrences of:

a.example.com

with

b.example.com

within a text file under the /home/user/ directory tree recursively finding and replacing all occurrences in all files in sub-directories as well.

+1  A: 

Try this: find /home/user/ -type f | xargs sed -i 's/a.example.com/b.example.com/g'

vehomzzz
Will this replace the string in every file under the /home/user directory? Including sub-directories?
Tony
Yes it will, though you should specify some sort of pattern -name 'pattern' after find
vehomzzz
what do you mean "some sort of pattern"?
Tony
A pattern like `-name 'pattern'` - where "pattern" might be like "domainlist*" - something that narrows down the search.
Dennis Williamson
A: 

Exact duplicate of this question.

Employed Russian
Your comment should be posted as a comment rather than an answer.
Dennis Williamson