1

I have a file which I'd like to parse to extract certain values from it. I don't know what command and syntax I should use (maybe sed?).

Below are 2 sample lines which I might expect to find in the file. What I need is the value of name (i.e 1234 and xyz respectively in the example) as well as the value of jndiName.

factories xmi:type="resources.url:URL" xmi:id="" name="1234" jndiName="xyz_aBC" 

factories xmi:type="resources.url:URL" xmi:id="URL_1323780357724" name="xyz" jndiName="abc" 

If I use sed, how would I apply it in this situation?

aculich
  • 3,520
  • 1
  • 25
  • 33
dhruv
  • 11
  • 1

3 Answers3

1

Generally it is considered unwise to try and parse xml using standard unix utilities. I have used the xml2 utility to parse xml files and then use grep/awk/sed etc to do what I want.

user9517
  • 114,104
  • 20
  • 206
  • 289
0

xmlstarlet is also a good alternative for parsing xml in shell if for religious reasons one can not use e.g. perl XML::Simple ;)

Aleksandar Ivanisevic
  • 3,327
  • 19
  • 24
0

By hinting that you might consider using regular expressions (sed) to parse an xml file you've uttered an incantation that will lead you into the mouth of madness! Please turn back!

aculich
  • 3,520
  • 1
  • 25
  • 33