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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing all at once

Status
Not open for further replies.

blueeyedme

Technical User
Nov 27, 2002
39
0
0
NL
Question,

I got a directory full of script who mail output to specific email adresses. But ! our domain name is going to change so i need to change all the adresses from user@olddomain to user@newdomain.com. Some scripts area already changed.

Can anybody help me with this ?

thanks !

Jeroen
 
What I would do is:

# grep for olddomain in all files and print only file names to variable each_file
for each_file in `fgrep -l olddomain *`
do
# sed olddomain to newdomain for each filename in variable each_file
sed 's/olddomain/newdomain/g' $each_file > ${each_file}.tmp
mv ${each_file}.tmp $each_file
done

Since you probably have more than one user for user@olddomain.com, I would just grep out the domain name minus the ".com". Hope this helps.
aithosn8
aithosn8@lycos.com

"Impossible is a word to be found only in the dictionary of fools." - Napoleon Bonaparte

 
Hi there,

The solution given by aithosn8 is perfect. Only the thing he forgot to consider is the permissions on the files. Looking after the requirement, I felt that it shouldn't get changed.
In aithosn8's script, the file will be recreated. But will have the default permissions.
Please check.
In one of my project, I had to do the same thing. I remember, for maintaining the old permissions I had used 'ed' instead of 'sed'. Right now I dont have access to Unix box, so cant give the actual script. But at least u have a clue now.

Thanks.

ViolinDude
 
Cool both thanks for the reply's. I think i can come really far with this. THANKS !!! ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top