0

I am having issues while I am trying to get some data from the text filed of the xml tag.

This filed is repeated many times in the xml.

<abc>
<def>
<gh tag="ext" text="1. look
2. for 
3. this 
4. if
5. what">
</gh>
</def>
</abc>

What I have done is to grep the pattern and loop till the "> reached. But I am also getting some other data also. Can someone please help me with that or show me the direction. I tried perl but XML library where missing.

1
  • Perl modules can be installed in your home directory. You don't have to install them in a "system" location. Commented Mar 10, 2011 at 17:28

4 Answers 4

3

Please use the correct tool.

$ xmlstarlet sel -t -m abc/def/gh -v @text input.xml
1. look 2. for 3. this 4. if 5. what
Sign up to request clarification or add additional context in comments.

2 Comments

i am not having this tool on my server. and dnont have permission to install anything
Then you're screwed. Have fun.
1

You might be able to adapt the AWK script found here.

Comments

1

sgrep - Structured Grep - used in searching and indexing XML , HTML.

http://www.cs.helsinki.fi/u/jjaakkol/sgrepexamples.html

Comments

0

A quick and dirty solution -

awk '/text="/,/">/{print}' xmlfile | sed -e 's/^\(<gh.*="\)//' -e 's/">$//'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.