General discussion

Locked

Read a xml file to get some information from it

By avazquez65 ·
have a xml file with the following format:

<? (Line 1)
xml (Line 2)
version="1.0" (Line 3)
encoding="UTF-8"?><res:FormalIDNotification (Line 4)

IEO_FormalID_DataTypes.xsd'><Importer><AddressInfo><ContactName>first
last</ContactName><CompanyName>company</CompanyName><AddressLine1>addr1</Address
Line1><AddressLine2>addr22222</AddressLine2><AddressLine3>addr3333</AddressLine3
City>Brisbane</City><PostalCode>000</PostalCode><CountryCode>AU</CountryCode
PhoneNumber>12345</PhoneNumber><PhoneExtension>123</PhoneExtension><FaxNumber>12
345</FaxNumber><Email>email@au.com</Email></AddressInfo><OtherInfo><SiteID>I7560
</SiteID></OtherInfo></Importer><Consignee><AddressInfo><ContactName>brazil1</Co
ntactName><CompanyName>ggh</CompanyName><AddressLine1>rrtrt</AddressLine1><City>
sape</City><PostalCode>58340</PostalCode><CountryCode>BR</CountryCode><PhoneNumb
er>67778879</PhoneNumber><Email>gghj@jjk.com</Email></AddressInfo><CnpjCpfInfo
CnpjCpfId>25211178890</CnpjCpfId><CnpjCpfTaxType>CPF</CnpjCpfTaxType></CnpjCpfIn
fo></Consignee><Shipper><AddressInfo><ContactName>test</ContactName><CompanyName
>ggh</CompanyName> (This is line 5, it is even largest )

Requiriment:

I need to get is the following information: first last from the first label <ContactName>, and test from third label <ContactName>, company from the first label <CompanyName>, and ggh from the third label <CompanyName> and so on other information.

Problem:

I created a unix script file to read it using grep as follow:

grep <ContactName> filename.xml | cut -d\> -f2|cut -d\< -f1

and the result is the whole line in Line 5 described previously. How can I filter just to get the information I need from the file!?!?.

I will really appreciate your help to solve this problem.

Thank You!

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Linux Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums