Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

After a bit of googling / research on my own i haven't found a definitive answer,

I'm looking to search the entire /var/www/html/ folder for occurances of "127.0.0.1" and replace them with a server IP address (we're moving the database off of the local box).

This goes for Localhost & 127.0.0.1. While i could just run

find * | xargs sed -i a/127.0.0.1/ser.ver.ip.addr/g

twice, once replacing 127.0.0.1 and localhost, i'd rather not have to run two commands.

Am i able to do a OR statement without it breaking?

Something like:

find * | xargs sed -i a/127.0.0.1|localhost/ser.ver.ip.addr/g

----------------------------edit----------------------

I found a slightly more reliable method of doing a search & replace,

find * -type f -exec sed -i 's/127.0.0.1/ser.ver.ip.addr/g' {} \;

However i can't seem to get the search statement to match 127.0.0.1 OR localhost.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
find . -type f -print | xargs sed -i -e 's/127.0.0.1/207.200.19.177/g' -e 's/localhost/207.200.19.177/g'
share|improve this answer
add comment

I think you would have to put it in quotes:

find * | xargs sed -i "a/127.0.0.1|localhost/ser.ver.ip.addr/g"
share|improve this answer
    
and of course: find . -type f –  chris Jul 6 '09 at 23:17
    
with or without quotes / ticks it seemed to work. –  GruffTech Jul 6 '09 at 23:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.