Source xml file splitter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Source xml file splitter
# 8  
Old 10-17-2012
It will be difficult for me to justify business but even minimizing word length, Its giving same error for large source file. its running fine for small file.
# 9  
Old 10-17-2012
Quote:
Originally Posted by santosh2k2
It will be difficult for me to justify business but even minimizing word length, Its giving same error for large source file. its running fine for small file.
try with this..

Might be we are trying to write to the x which is not present..Smilie

Code:
word='<?xml version="1.0" encoding="utf-8"?>'
 
awk -v serch="$word" '{if($0 ~ serch){x="'"${SrcFileName}_"'" sprintf("%04d",++i) ".txt";print > x}else if(x){print > x}}' $SrcFileName.txt

# 10  
Old 10-17-2012
code ran successfully with writing any new file.. so basically no output file is generated.

---------- Post updated at 11:07 AM ---------- Previous update was at 10:37 AM ----------

earlier code which exilir gave is working but wanted to parameterise word. can awk script be changed to use word parameter

Code:
SrcFileName=XML_DUMP
word='<?xml version="1.0" encoding="utf-8"?>'
 
awk '/<\?xml version="1\.0" encoding="utf-8"\?>/{n++} 
n{f="'"${SrcFileName}_"'" sprintf("%04d",n) ".txt"
print >> f
close(f)}' $SrcFileName.txt

# 11  
Old 10-18-2012
You need to use double slash Smilie

try

Code:
word='<\\?xml version="1\\.0" encoding="utf-8"\\?>'

awk -v serch="$word" '{if($0 ~ serch){x="'"${SrcFileName}_"'" sprintf("%04d",++i) ".txt";print > x}else if(x){print > x}}' $SrcFileName.txt


Last edited by pamu; 10-18-2012 at 03:29 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies

2. Shell Programming and Scripting

Comparing delta values of one xml file in other xml file

Hi All, I have two xml files. One is having below input <NameValuePair> <name>Daemon</name> <value>tcp:7474</value> </NameValuePair> <NameValuePair> <name>Network</name> <value></value> </NameValuePair> ... (2 Replies)
Discussion started by: sharsour
2 Replies

3. Shell Programming and Scripting

File splitter

I have below script which does splitting based on a different criteria. can it be amended to produce required result SrcFileName=XML_DUMP awk '/<\?xml version="1\.0" encoding="utf-8"\?>/{n++} n{f="'"${SrcFileName}_"'" sprintf("%04d",n) ".txt" print >> f close(f)}' $SrcFileName.txt My... (3 Replies)
Discussion started by: santosh2k2
3 Replies

4. Shell Programming and Scripting

File Splitter output filename

Issue: I am able to split source file in multiple files of 10 rows each but unable to get the required outputfile name. please advise. Details: input = A.txt having 44 rows required output = A_001.txt , A_002.txt and so on. Can below awk be modified to give required result current... (19 Replies)
Discussion started by: santosh2k2
19 Replies

5. Shell Programming and Scripting

Text Splitter

Hi, I need to split files based on text: BEGIN DSJOB Identifier "LA" DateModified "2011-10-28" TimeModified "11.10.02" BEGIN DSRECORD Identifier "ROOT" BEGIN DSSUBRECORD Owner "APT" Name "RecordJobPerformanceData" Value "0" ... (16 Replies)
Discussion started by: unme
16 Replies

6. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

7. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

8. Shell Programming and Scripting

I need script to get xml access export from source server

Hi, I need a shell script to create to get XML access export from the source server. Thanks in Advance (3 Replies)
Discussion started by: bcb
3 Replies

9. Shell Programming and Scripting

File splitter by nth row

I need to split a file into n separate files of about the same size. The way the file will be split is at every nth row, starting with the first row, that row will be cut and copied to it's corresponding new file so that each file has unique records. Any 'leftovers' will go into the last file. e.g.... (4 Replies)
Discussion started by: sitney
4 Replies

10. Shell Programming and Scripting

Help needed in writing awk script for xml source

Hi, i am not able to get an approach for converting xml file to flat file using awk programming. Can anyone help me out. The input xml is like this: <outer> <field1>one</field1> <field2>two</field2> <field3>three<Error Code=777 Description=12345/></field3> <field4>four</field4> </outer>... (2 Replies)
Discussion started by: naren_0101bits
2 Replies
Login or Register to Ask a Question