How to get value from xml node using sed/perl/script?

hello,

new to this forum. but i have a requirement to extract the value from multiple xml node and print out the values to new file with comma seperated. would like to know how this would be done using either sed/perl or some unix script. an example would be tremendous...

sample input file:

<city>sacramento</city><state>california</state><zip>95835</zip>
<city>sanjose</city><state>california</state><zip>95121</zip>
<city>honolulu</city><state>hawaii</state><zip>86021</zip>

requirement : get city & zip values and print to new file
-----------------------------------------------------

output should look like this:

sacramento,95835
sanjose,95121
honolulu,86021
sed 's/<city>\(.*\)<\/city>.*<zip>\(.*\)<\/zip>.*/\1,\2/' file
1 Like

thank you so much for the reply and works great for the example I gave earlier. As I was going through your example, I am a little confused as to what it all means. I tried some variations on another set of data and the script seems to break or not bringing back the correct result. Take a look @ the attachment. It is 1 record with many xml tags. However, I want to retrieve the following from the record:

1) <ResultCode></ResultCode>
2) <requestID></requestID>
3) <SitePartyId></SitePartyId>
4) <AddressUsageType></AddressUsageType>

Can you provide a solution for this? Thank you kindly.