I'm working to replace a large set of TTLs inside some tinydns zonefiles. Regardless of what the TTL is currently set to, I want it to become 900. I'm looking for some sed magic, and I'm almost there it seems.
I have about 50 hostnames to replace the TTL, and the zones are sporadically assigned.
The lines in the zonefiles don't need to contain a TTL. If they don't have it, the TTL will need to be appended. In other words, the lines that I will be searching through look as follows:
^.*hostname:(hostname|IP)[:#]$
e.g.
+abc.com:12.12.12.12 =*.abc.com:x.y.z.com:1200
So I need help with constructing the regular expression for my sed command. It's going to be something like:
cat hosts.txt | while read host; do sed -i 's/'$host':([^:]*)(?:[0-9]*)/'$host':\1:900/' zonefile* done
Any sed gurus feeling generous?