Split large zone file dump into multiple files


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-21-2011
Split large zone file dump into multiple files

I have a large zone file dump that consists of

Code:
; 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 Smilie
# 3  
Old 12-21-2011
here is the code u needed :-)

Code:
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

# 4  
Old 12-21-2011
Another approach:

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

# 5  
Old 12-21-2011
Quote:
Originally Posted by Franklin52
Another approach:

Code:
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.
# 6  
Old 12-21-2011
Quote:
Originally Posted by Bluemerlin
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.
Sure.
Code:
awk '/; DNS/{f=$(NF-1)}{print > f}' file

Explanation:
Code:
/; 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"

# 7  
Old 12-21-2011
Quote:
Originally Posted by Franklin52
If the line begins with "; DNS"
To be precise the regular expression translates to "If the line contains anywhere "; DNS""
This User Gave Thanks to bartus11 For This Post:
Franklin52 (12-21-2011)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Split large xml into mutiple files and with header and footer in file karthik Shell Programming and Scripting 36 19 Hours Ago 01:33 AM
Split large file into smaller files without disturbing the entry chunks Kamesh G UNIX for Beginners Questions & Answers 12 05-10-2018 05:39 AM
Split a large textfile (one file) into multiple file to base on ^L fspalero Linux 3 04-14-2016 04:34 AM
Help needed - Split large file into smaller files based on pattern match frustrated1 Shell Programming and Scripting 7 01-18-2013 06:02 PM
Issues restoring a large dump file Nobody_knows_me Red Hat 0 10-03-2012 03:45 PM
split file into multiple files jacobs.smith Shell Programming and Scripting 2 04-03-2012 11:28 AM
Solaris 10 zone crash dump file? fastexit Solaris 4 09-13-2010 07:42 AM
Split file into multiple files jdhahbi Shell Programming and Scripting 2 08-23-2010 10:40 PM
Split a file into multiple files pparthji Shell Programming and Scripting 24 12-30-2009 09:54 AM
multiple smaller files from one large file rtroscianecki UNIX for Dummies Questions & Answers 2 07-15-2009 11:25 PM
split a file into multiple files kumar66 UNIX for Dummies Questions & Answers 8 10-23-2008 05:25 PM
Split a file into multiple files glamo_2312 Shell Programming and Scripting 3 09-15-2008 10:58 AM
Split large file and add header and footer to each small files ashish4422 Shell Programming and Scripting 7 07-07-2008 03:13 PM
Copy large dump file ganga.dharan Shell Programming and Scripting 4 04-07-2008 06:26 PM
how to divide single large log file into multiple files. kamleshm Shell Programming and Scripting 1 01-15-2008 07:33 PM