Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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

Your Answer


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.