I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it.
For example, Here is a portion of a zone file.
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN NS ns3.domain.tld.
IN NS ns4.domain.tld.
IN A 255.255.255.255
I need to add 4 lines of MX records in between the final NS record and the first A record, and still leave 1 line of white space between each, so that it looks like this:
IN NS ns1.domain.tld.
IN NS ns2.domain.tld.
IN NS ns3.domain.tld.
IN NS ns4.domain.tld.
IN MX mx1.domain.tld.
IN MX mx2.domain.tld.
IN MX mx3.domain.tld.
IN MX mx4.domain.tld.
IN A 255.255.255.255
I've checked the other posts which have to do with inserting text into a file, and it seems like this can be done with some iteration of sed, but I'm not sure where to begin. the other examples of this kind of situation on this forum seemed to be dealing mostly with specific line numbers, or a static value to insert the line after. Where in this situation, the final NS record will change, and the amount of NS lines will change from zone file to zone file, so the only static value is the IN NS.
any help anyone can offer with this is greatly appriciated.