Trying to parse a xml file for only one tag

I have a xml file in where I need to parse only a particular tag and print the output in the shell script.

Here is the tag info in the xml file

<dp:file> This is dp file output </dp:file>

Output should be printed as

This is dp file output.

Please help.Thank you.

This is one way using sed:

$ echo '<dp:file> This is dp file output </dp:file>' | sed -n 's/<dp:file>\(.*\)<\/dp:file>/\1/p'
 This is dp file output

Example of running command on file:

sed -n 's/<dp:file>\(.*\)<\/dp:file>/\1/p' file_name.xml
1 Like

Using awk:-

awk -F'[<|>]' '/dp:file/ { print $3 } ' xml_file
1 Like

We need to see more of the XML.

1 Like

Thank you all for the response..I will keep this open for one more day...I will try in the script and will keep you guys posted.

Thank you!!

perl -lne "if(/dp:file/){$_=m/>([^<]*)</;print $1}" your_xml_file

Regard's,
Vijay