ulink
asked on
Linux find and replace for lines containing specific text
I need to change MX records across a large amount of domains and I am looking for a script to automate the process. The problem lies in that I need to change the MX record, but not cname records. For example:
From
@ IN MX 100 mail.somedomain.com
@ IN MX 100 mail.somedomain.com
mail1 IN CNAME mail.somedomain.com
mail2 IN CNAME mail.somedomain.com
To
@ IN MX 100 mail.newdomain.com
@ IN MX 100 mail.newdomain.com
mail1 IN CNAME mail.somedomain.com
mail2 IN CNAME mail.somedomain.com
So basically I need something that says go through every file in this folder and look for lines containing MX. On those lines, replace mail.somedomain.com with mail.newdomain.com
From
@ IN MX 100 mail.somedomain.com
@ IN MX 100 mail.somedomain.com
mail1 IN CNAME mail.somedomain.com
mail2 IN CNAME mail.somedomain.com
To
@ IN MX 100 mail.newdomain.com
@ IN MX 100 mail.newdomain.com
mail1 IN CNAME mail.somedomain.com
mail2 IN CNAME mail.somedomain.com
So basically I need something that says go through every file in this folder and look for lines containing MX. On those lines, replace mail.somedomain.com with mail.newdomain.com
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sed 's/mail.somedomain.com/mai l.newdomai n.com/' MX_file > tmp_file
mv tmp_file MX_file
mv tmp_file MX_file
perl -pi -w -e 's/mail\.somedomain\.com/m ail\.newdo main\.com/ g;' *
ASKER
Worked beautifully, thanks
< From > To