Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Split large zone file dump into multiple files


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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  
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

# 5  
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  
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  
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 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
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>...... Shell Programming and Scripting
36
Shell Programming and Scripting
Split large file into smaller files without disturbing the entry chunks
Kamesh G
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...... UNIX for Beginners Questions & Answers
12
UNIX for Beginners Questions & Answers
Split a large textfile (one file) into multiple file to base on ^L
fspalero
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 ==========... Linux
3
Linux
Help needed - Split large file into smaller files based on pattern match
frustrated1
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...... Shell Programming and Scripting
7
Shell Programming and Scripting
Split large file and add header and footer to each small files
ashish4422
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?... Shell Programming and Scripting
7
Shell Programming and Scripting

Featured Tech Videos