parsing xml with awk/sed

Hi people!,

I need extract from the file (test-file.txt) the values between
<context> and </context> tag's , the total are 7 lines,but i can only get 5 or 2 lines!!:confused:

Please look my code:

#awk '/context/{flag=1} /\/context/{flag=0} !/context/{ if (flag==1) p
rint $0; }' test-file.txt |wc -l

this return 5 lines

#awk '/context/{gsub(/<|>|\/|context/,"");print} ' test-file.txt|grep
. |wc -l

this return 2 lines that i can't get from the first try.

Best Regards,
-ric

A non-xml based solution is like this:

$ awk '/<context>/,/<\/context>/' test-file.txt | grep -v "context>"

But I am sure, there will be better solutions to this query. Lets think.

//Jadu

A similar one using sed:

$ sed -n '/<context>/,/<\/context>/p' test-file.txt | sed -e '/<context>/d' -e '/\/context/d'

//Jadu

Thanks for your help Jadu!!,works great!! :slight_smile:
Best Regards,
-ric