Split large zone file dump into multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split large zone file dump into multiple files
# 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
# 2  
Old 12-21-2011
Try:
Code:
awk -vRS=";" '/./{print $0 > $5}' dumpfile

# 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:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split large file into 24 small files on one hour basis

I Have a large file with 24hrs log in the below format.i need to split the large file in to 24 small files on one hour based.i.e ex:from 09:55 to 10:55,10:55-11:55 can any one help me on this.! ... (20 Replies)
Discussion started by: Raghuram717
20 Replies

2. Shell Programming and Scripting

Split large xml into mutiple files and with header and footer in file

Split large xml into mutiple files and with header and footer in file tried below it splits unevenly and also i need help in adding header and footer command : csplit -s -k -f my_XML_split.xml extrfile.xml "/<Document>/" {1} sample xml <?xml version="1.0" encoding="UTF-8"?><Recipient>... (36 Replies)
Discussion started by: karthik
36 Replies

3. UNIX for Beginners Questions & Answers

Split large file into smaller files without disturbing the entry chunks

Dears, Need you help with the below file manipulation. I want to split the file into 8 smaller files but without cutting/disturbing the entries (meaning every small file should start with a entry and end with an empty line). It will be helpful if you can provide a one liner command for this... (12 Replies)
Discussion started by: Kamesh G
12 Replies

4. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

5. Shell Programming and Scripting

Help needed - Split large file into smaller files based on pattern match

Help needed urgently please. I have a large file - a few hundred thousand lines. Sample CP START ACCOUNT 1234556 name 1 CP END ACCOUNT CP START ACCOUNT 2224444 name 1 CP END ACCOUNT CP START ACCOUNT 333344444 name 1 CP END ACCOUNT I need to split this file each time "CP START... (7 Replies)
Discussion started by: frustrated1
7 Replies

6. Solaris

Solaris 10 zone crash dump file?

Hi, I'm running Solaris 10 with a zone called "testzone" If I do a "reboot -d" on the host, as expected the kernet panics, reboots and creates a crash dump file in /var/crash However no crash file is created in testzone. My question is how can I tell if a zone crashs or shuts down... (4 Replies)
Discussion started by: fastexit
4 Replies

7. UNIX for Dummies Questions & Answers

multiple smaller files from one large file

I have a file with a simple list of ids. 750,000 rows. I have to break it down into multiple 50,000 row files to submit in a batch process.. Is there an easy script I could write to accomplish this task? (2 Replies)
Discussion started by: rtroscianecki
2 Replies

8. Shell Programming and Scripting

Split large file and add header and footer to each small files

I have one large file, after every 200 line i have to split the file and the add header and footer to each small file? It is possible to add different header and footer to each file? (7 Replies)
Discussion started by: ashish4422
7 Replies

9. Shell Programming and Scripting

Copy large dump file

Hi Experts.. Could anyone please let me know the easier way to copy large dump of files from one server to another. I am trying to copy a set of dump files on two different servers placed in different geographic locations.. Though there are other factors such as latency, etc., slowing up the... (4 Replies)
Discussion started by: ganga.dharan
4 Replies

10. Shell Programming and Scripting

how to divide single large log file into multiple files.

Can you please help me with writing script for following purpose. I have to divide single large web access log file into multiple log files based on dates inside the log file. For example: if data is logged in the access file for jan-10-08 , jan-11-08 , Jan-12-08 then make small log file... (1 Reply)
Discussion started by: kamleshm
1 Replies
Login or Register to Ask a Question