Rapid DNS Zone serial update
Today, while doing a DNS server migration, I found myself having to update a bunch of DNS zone files. First, I had to change the ip address for some records in every zone file (as the DNS server is a web server too, so moving the server means I had to move every web service there too). That was pretty easy (as I've done it before).
But then I realized I had to update the serial code for each zone file too, and that would be a little bit tricky, as each zone had a different serial code. Of course, sed to the rescue again!, the one-liner:
sed -i.bak '/serial/s/[0-9][0-9]*/2009022701/' *
and et voilá, all the serial codes are changed into 2009022701, doing a .bak backup of the file before changing it. Basically, it search for lines that match the serial term and then it replaces each numeric code with the new one.
(borrowed from here)