Click to See Complete Forum and Search --> : bash script question???


shaggy112
06-10-2001, 09:35 PM
I am using rsync to sycronize a server running apache to serve a web site.

The problem is that in the html code, the actual fqdn is referenced.

I want to script something that will grep each file in a specific dir where the code is held, and change it to the ip of the server that I am syncing.

Hope this makes sense.
Thanks

EscapeCharacter
06-10-2001, 09:56 PM
you could try something like
cat file|awk s/oldip/newip/g >file
(or is that suppose to be sed?)

Craig McPherson
06-10-2001, 10:27 PM
I'd use sed for that. Awk might be able to do that too, but it's mainly for something different...

shaggy112
06-11-2001, 11:05 PM
thanks for the replies.

I try this:
cat file | sed s/oldip/newip/

It scrolls accross the screen the correct output (as in oldip is changed to newip), but the file itself is untouched.

I tried '...> file', but that didn't do it either.
Any addl help would be great
Thanks!

Calvin_1976
06-12-2001, 06:54 AM
Try

sed -e s/oldip/newip/ filename | tee filename

shaggy112
06-12-2001, 08:35 AM
calvin,

thanks. that worked except when there was more than one occurence in one line. in other words....when i had the ip twice or more, it would only change the first.

thanks

Strike
06-12-2001, 12:17 PM
put a "g" at the end of the sed expression:

sed -e s/oldip/newip/g filename | tee filename

This means "global" replacing.

shaggy112
06-13-2001, 09:17 AM
thanks.

this works great.

one other question though. How do I make it do things recursively...as in whole directories at a time? I thought that a star might work but it did not. Any ideas?
thanks