Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Can you give us some valid xml to work with ? –  Iain Jan 22 '12 at 17:25
add comment

3 Answers

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.