How to read an Xml record contained in a file--urgent


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to read an Xml record contained in a file--urgent
# 1  
Old 06-18-2008
How to read an Xml record contained in a file--urgent

Hi
I have an xml file which has multiple xml records..
I don't know how to read those records and pipe them to another shell command

the file is like

<abc>z<def>y<ghi>x........</ghi></def></abc> (1st record)
<jkl>z<mno>y<pqr>x........</pqr></mno></jkl> (2nd record)

Each record end with a "newline" character i belive but i am not able to see the newline character..
I used cat -vte command to view it

I am planning to grep the record by means of a common string
say "Z" found in all the records..

take the count of the number of records and then send each record by reading one at a time..and then pipe it to say a "sed" command...


Is there a mechanism...can somebody help out..


Thanks in advance!!!
# 2  
Old 06-18-2008
If the XML is not conveniently line-oriented, you best bet is probably to use a real XML parser to extract the stuff you want. You might end up not wanting to use the shell or sed at all once you figure it out, although the learning curve might seem a bit steep at first. Search for threads demonstrating the use of e.g. xsltproc
# 3  
Old 06-18-2008
Ya thats fine ...but i want some script statements that would conveniently help me parse the file containing the xml records record by record..
# 4  
Old 06-18-2008
Another way around if i think of the information that i have provided above is that..say
I have certain information within the tag

<PQRS><ABCD>hi how r u</ABCD></PQRS>
and i need to exract this info and pipe it to another sed command for futher formatting

can xsltproc as suggested by era help in any way? Can any one suggest doing that


I need to extract day from only 1 tags say <ABCD></ABCD> and this tags is enclosed within others..

Can some 1 suggest a way to extract onlt this 1 tag's data ...

I have already succesfully tried sed command and ...but the command is failng when the tag is occuring in a large xml record...I mean a particular record is
occuring which is unusually large in its size

Last edited by aixjadoo; 06-18-2008 at 04:53 AM..
# 5  
Old 06-19-2008
Unless your XML document is very small, you should use an XML processor to extract the required elements and attributes. Classic UNIX tools such as sed and awk are not really suited to manipulating XML documents nor were they designed or intended for this purpose.

xsltproc is one such processor which uses an XSL stylesheet to transform the document into the required output. There are a large number of other XML document transformation tools available. Just do a Web search.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

2. Shell Programming and Scripting

Update file record inside read loop

Hi, I am reading file records inside a while loop, and want to update the record when certain condition is met. How can I update a file while being read? I want to avoid using temporary files, copy, rename, ... while IFS=',' read -r f1 f2 do function(f1,f2) if then <add... (1 Reply)
Discussion started by: ysrini
1 Replies

3. UNIX for Dummies Questions & Answers

Delete a record in a xml file using shell scripting

find pattern, delete line with pattern and 3 lines above and 8 lines below the pattern. The pattern is "isup". The entire record with starting tag <record> and ending tag </record> containing the pattern is to be deleted and the rest to be retained. <record> ... (4 Replies)
Discussion started by: sdesstp
4 Replies

4. Shell Programming and Scripting

Bash Script to read a file and parse each record

Hi Guys, I am new to unix scripting and I am tasked to parse through a CSV file delimited by #. Sample: sample.csv H#A#B#C D#A#B#C T#A#B#C H = Header D = Detail Record T = Tail What I need is to read the file and parse through it to get the columns. I have no idea on how... (8 Replies)
Discussion started by: 3vilwyatt
8 Replies

5. Shell Programming and Scripting

Read the record from a text file

Hi I want to read one row record from a text file. For eg: I have Sample.txt file with one row of record like 123456768 I want to get the above value from the file and assign it to a variable in my script. Please guide me how to proceed. Thanks, Soll (2 Replies)
Discussion started by: sollins
2 Replies

6. UNIX for Advanced & Expert Users

Shell script failing to read large Xml record-urgent critical help

Hi All, I have shell script running on AIX 5.3 box. It has 7 to 8 "sed" commands piped(|) together. It has a an Xml file as its input which has many records internally. There are certain record which which have more than hundered tags.The script is taking a huge amount of time more than 1.5 hrs... (10 Replies)
Discussion started by: aixjadoo
10 Replies

7. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

8. Shell Programming and Scripting

read record from file

Hi all I have file f1 like this: Set AM/PM indicator to PM started|14155| Generate Error Re|7| Projected Cash Ba|741| Roll System Date |4| Projected Cash Balances started|2| Process Mark To Market started|13429| Process paydowns started|14189| Process Fixed Inc|439| Process Mark To... (3 Replies)
Discussion started by: koti_rama
3 Replies

9. Shell Programming and Scripting

Urgent!!!Read directory from a file

I have a receive script file which had lots of direcorties to process,but now,I don't want to hardcode them,I need input the directory name in a Property.txt file,then write shell code to read the directory name from Property.txt to the script file so I can get flexible on it.But when I ran the sh... (3 Replies)
Discussion started by: joshuaduan
3 Replies

10. Shell Programming and Scripting

remove duplicated xml record in a file under unix

Hi, If i have a file with xml format, i would like to remove duplicated records and save to a new file. Is it possible...to write script to do it? (8 Replies)
Discussion started by: happyv
8 Replies
Login or Register to Ask a Question