Split large zone file dump into multiple files

I have a large zone file dump that consists of

; DNS record for the adomain.com domain
data1
data2
data3
data4
data5
CRLF
CRLF
CRLF
; DNS record for the anotherdomain.com domain
data1
data2
data3
data4
data5
data6
CRLF
CRLF
CRLF

I need to split it into multiple files the domain name as the file name.

Please help :slight_smile:

Try:

awk -vRS=";" '/./{print $0 > $5}' dumpfile

here is the code u needed :slight_smile:

while read line
do
        if grep -q -i "; DNS" <<<$line
        then
                name=$(echo "$line" | awk -F' ' '{print $6}')
        else
                echo "$line" >>  "$name"
        fi
 
done < inputfile

Another approach:

awk '/; DNS/{f=$(NF-1)}{print > f}' file

Thanks,

If it's not asking too much, could you explain this to me as I would like to understand and learn rather than just asking for another script for my next endeavor.

To be precise the regular expression translates to "If the line contains anywhere "; DNS""

1 Like

You're correct, thanks.

Sure.

awk '/; DNS/{f=$(NF-1)}{print > f}' file

Explanation:

/; DNS/{f=$(NF-1)}  |  If the line begins with "; DNS" then assign the domain name ( last field - 1) to the variable f

{print > f}  |  print the line to the file with the name of the variable "f"