how to get value of two tags of xml using sed -


i have xml files , want fetch values of tags. xml given below:

<?xml version="1.0" standalone = "no"?> <!doctype handover_list public"en""h"> <x1> <x2> <x3>usa</x3> <date_time>20170813t18:18-04:00</date_time> <id action="i">xxxxxxxxxxxxxx</id> <id action="i">yyyyyyyyyyyyyy</id> <id action="i">zzzzzzzzzzzzzz</id> </x2> <x2> <x3>uae</x3> <date_time>20160814t15:15-03:04</date_time> <id action="i">aaaaaaaaaaaaaa</id> <id action="i">bbbbbbbbbbbbbb</id> <id action="i">cccccccccccccc</id> </x2> </x1> 

what i'm using is:

sed -n 's:.*<x3>\(.*\)</x3>.*:\1:p' formated.xml sed -n 's:.*<id action="i">\(.*\)</id>.*:\1:p' formated.xml 

and given output this:

usa uae xxxxxxxxxxxxxx yyyyyyyyyyyyyy zzzzzzzzzzzzzz aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccc 

what want merge both sed commands used above can output this:

usa xxxxxxxxxxxxxx yyyyyyyyyyyyyy zzzzzzzzzzzzzz uae aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccc 

the right way using xml parsers xmlstarlet:

in such case, <doctype ..> tag redundant.

xmlstarlet sel -t -v '//x2/*[not(self::date_time)]' -n formated.xml 

the output:

usa xxxxxxxxxxxxxx yyyyyyyyyyyyyy zzzzzzzzzzzzzz uae aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccc 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -