XML files with spaces in the tag name, parse & display?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting XML files with spaces in the tag name, parse & display?
# 1  
Old 02-09-2017
XML files with spaces in the tag name, parse & display?

Greetings all,

I have an XML file that is being generated from my application, here is a sample of the first tag (That I am trying to remove and display in a list..)

Example-

Code:
<tag one= "data" data="1234"  updateTime="1300">
 <tag one= "data1" data="1234"  updateTime="1300">
 <tag one= "data2" data="1234"  updateTime="1300">
 <tag one= "data3" data="1234"  updateTime="1300">

My desired output is a text file that looks like this

Code:
data
 data1
 data2
 data3

Not sure what the best approach is with this because of the whitespace in tag one. perl/awk/sed?

Opinions would be useful! Thanks much!

Last edited by vgersh99; 02-09-2017 at 05:32 PM.. Reason: code tags, please!
# 2  
Old 02-09-2017
Hello jeffs42885,

Could you please try following and let me know if this helps you.
Code:
awk '{sub(/.[^"]*"/,"");sub(/".*/,"");print}'   Input_file

Thanks,
R. Singh
# 3  
Old 02-09-2017
Code:
awk -F'"' '{print $2}' myFile
sed 's/[^"]*"\([^"]*\).*/\1/' myFile

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 02-10-2017
Excellent, thank you very much vgersh99. I still need to massage the file a bit but this is a major push in the right direction. thank you!
# 5  
Old 02-10-2017
In the future please post what the file actually looks like, not an idealized depiction, so that we may write code which actually works.
# 6  
Old 02-10-2017
Apologies. Thank you for clarifying. Here is the output that I am now working with. Much better than before!

Keep in mind, this was generated with a part of my utility that generates an XML report.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find files in sub dir with tag & add "." at the beginning [tag -f "Note" . | xargs -0 {} mv {} .{}]

I am trying find files in sub dir with certain tags using tag command, and add the period to the beginning. I can't use chflags hidden {} cause it doesn't add period to the beginning of the string for web purpose. So far with my knowledge, I only know mdfind or tag can be used to search files with... (6 Replies)
Discussion started by: Nexeu
6 Replies

2. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

3. Shell Programming and Scripting

To search for a particular tag in xml and collate all similar tag values and display them count

I want to basically do the below thing. Suppose there is a tag called object1. I want to display an output for all similar tag values under heading of Object 1 and the count of the xmls. Please help File: <xml><object1>house</object1><object2>child</object2>... (9 Replies)
Discussion started by: srkmish
9 Replies

4. Shell Programming and Scripting

XML Parse between to tag with upper tag

Hi Guys Here is my Input : <?xml version="1.0" encoding="UTF-8"?> <xn:MeContext id="01736"> <xn:VsDataContainer id="01736"> <xn:attributes> <xn:vsDataType>vsDataMeContext</xn:vsDataType> ... (12 Replies)
Discussion started by: pareshkp
12 Replies

5. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

6. Emergency UNIX and Linux Support

Trying to parse a xml file for only one tag

I have a xml file in where I need to parse only a particular tag and print the output in the shell script. Here is the tag info in the xml file <dp:file> This is dp file output </dp:file> Output should be printed as This is dp file output. Please help.Thank you. (5 Replies)
Discussion started by: chandu123
5 Replies

7. Shell Programming and Scripting

awk Script to parse a XML tag

I have an XML tag like this: <property name="agent" value="/var/tmp/root/eclipse" /> Is there way using awk that i can get the value from the above tag. So the output should be: /var/tmp/root/eclipse Help will be appreciated. Regards, Adi (6 Replies)
Discussion started by: asirohi
6 Replies

8. Shell Programming and Scripting

How to retrieve the value from XML tag whose end tag is in next line

Hi All, Find the following code: <Universal>D38x82j1JJ </Universal> I want to retrieve the value of <Universal> tag as below: Please help me. (3 Replies)
Discussion started by: mjavalkar
3 Replies

9. Shell Programming and Scripting

Rename files with tag in a .xml file

Hi Guys! 1st of all, i am sorry for my bad english! I got a Sat-Receiver and i recorded some Stuff for my Children, now the Harddrive is full and i want to convert and rename it, that i can put it on DVDs But I've got a big Problem! I want to rename the files , with a tag in a xml file... (4 Replies)
Discussion started by: crusty
4 Replies
Login or Register to Ask a Question