I am looking for a solution to replace one pattern on a file except one line in it.
> cat /var/named/test.com.db
; cPanel first:11.11.0-BETA_16994 (update_time):1468656855 Cpanel::ZoneFile::VERSION:1.3 hostname:server.test.com latest:188.8.131.52
; Zone file for test.com
test.com. 86400 IN SOA ns1.test.com. cpanel.test.com. (
2016071602 ;Serial Number
test.com. 14400 IN A 192.168.1.100
localhost 14400 IN A 127.0.0.1
test.com. 14400 IN MX 0 test.com.
mail 14400 IN CNAME test.com.
www 14400 IN CNAME test.com.
ftp 14400 IN CNAME test.com.
webdisk 14400 IN A 192.168.1.100
cpcalendars 14400 IN A 192.168.1.100
test.com. IN TXT "v=spf1 +a +mx +ip4:192.168.1.100 ~all"
sed '/spf/! s/192\.168\.1\.100/192.168.1.101/'
On lines which do not match
/spf/ do the requested substitution. The backslashes prevent the
. from matching any character, of course. If you have any lines where the IP address could appear multiple times, you could add a
g at the end. If you think it is a real problem, you could worry about matching
9192.168.1.1001 (that is, you if you think the IP address might appear as a substring of something that isn't an IP address).