Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace throughout folder

Status
Not open for further replies.

cmhunt

Programmer
Apr 17, 2001
119
GB
Hi

Within our company we have had an ip address change to our internet server. There are many scripts throughout our system which use this ip which need changing. How can I replace all these values simply? I want to start at a high level folder and change any occurences in all files in all subfolders.

I hope someone can help.

Thanks

Chris
 
This should work..
This is all one command. The grep is to prevent a vi on files that don't contain the string.
example changes 123.456.789.10 to name.domain.com
Please tell me you are replacing the IP address with a domain name!!!




[tt]find . -type f -name '*'|xargs grep -lF 123.456.789.10 {} |xargs -t -I {} vi -c s/123.456.789.10/name.domain.com/g -c wq {} 2>IPchange.err[/tt]


Let me know if it works!
JRjr [morning]
 
No, replacing 192.1.2.11 with 192.1.2.13 so I guess

find . -type f -name '*'|xargs grep -lF 192.1.2.11 {} |xargs -t -I {} vi -c s/192.1.2.11/192.1.2.13/g -c wq {} 2>IPchange.err

would work?

Thanks

Chris
 


Yeah,

That sould work, but you really should look into managing this in /etc/hosts.

JRjr [morning]
 
Hi

This creates the file for the replace from the vi just fine with lines like:

vi -c s/123.456.789.0/987.654.321.0/g -c wq ./sfa/runfile.run

which look correct but doesn't work when running.

Any ideas??

Thanks

Chris
 
A slightly easier way:

Code:
find . -type f | xargs perl -i -p -e 's/foo/bar/g'

Where 'foo' is the old string, and 'bar' is the new string.

Hope this helps. Cheers, Neil :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top