Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting daa from XML file 2

Status
Not open for further replies.

omasnjak

Technical User
Jun 1, 2008
13
0
0
CZ
Hi people,

I am hopping someone has/had similar issue and will know how to get some data from file in format <item><label>1111</label><value>AAAA</value></item><item><label>2222</label><value>BBBB</value></item><item><label>3333</label><value>CCCC< and so on...
I am wondering how I can get this file when I say cat FILE_name | awk 'BEGIN {FS =" WHAT " .... ..

and get output like for example

1111 AAAA
2222 BBBB
3333 CCCC

it would help me a lot if someone know how to this make.
Thank you in advance everyone

 
Hi

A brutal way, tested on the provided data with [tt]gawk[/tt] and [tt]mawk[/tt] :
Code:
awk -vRS='</item>' '{gsub(/(<[^<>]+>)+/," ");sub(/^ +/,"")}1' /input/file

Feherke.
 
I know you asked in Awk forum, but this uses all UNIX utilities :)

Code:
tr ">" "\n" < input|grep -v '^<'|cut -d"<" -f1|paste - -

and it gives the output you need:)
 
Hi all,

thank you so much. You are fantastic. What feherke wrote is probably on some alien languag but it works perfectly.
Also to dstxaix, thank you very much you too.
Thank you very much.

I wish you all best.

Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top