0
基本上,我需要處理包含多個塊作爲單個文件中的輸出的XML文件響應。因此,我需要將各個塊轉換爲unix中的單獨行。需要將多個塊響應合併到單獨的行中
源數據:
<xml.ValidateAddressResponse xmlns="http://www.pb.com/spectrum/services/ValidateAddress">
<output_port>
<Address>
<Confidence>82</Confidence>
<RecordType>Normal</RecordType>
<CountryLevel>A</CountryLevel>
<ProcessedBy>USA</ProcessedBy>
<MatchScore>0</MatchScore>
<AddressLine1>1825 Kramer Ln</AddressLine1>
<City>Austin</City>
<StateProvince>TX</StateProvince>
<PostalCode>78758-4260</PostalCode>
<PostalCode.Base>78758</PostalCode.Base>
<PostalCode.AddOn>4260</PostalCode.AddOn>
<Country>United States Of America</Country>
<user_fields/>
</Address>
</output_port>
</xml.ValidateAddressResponse>
<xml.ValidateAddressResponse xmlns="http://www.pb.com/spectrum/services/ValidateAddress">
<output_port>
<Address>
<Confidence>82</Confidence>
<RecordType>Normal</RecordType>
<CountryLevel>A</CountryLevel>
<ProcessedBy>USA</ProcessedBy>
<MatchScore>0</MatchScore>
<AddressLine1>1825 Kramer Ln</AddressLine1>
<City>Austin</City>
<StateProvince>TX</StateProvince>
<PostalCode>78758-4260</PostalCode>
<PostalCode.Base>78758</PostalCode.Base>
<PostalCode.AddOn>4260</PostalCode.AddOn>
<Country>United States Of America</Country>
<user_fields/>
</Address>
</output_port>
</xml.ValidateAddressResponse>
輸出需要:
<xml.ValidateAddressResponse xmlns="http://www.pb.com/spectrum/services/ValidateAddress"><output_port><Address><Confidence>82</Confidence><RecordType>Normal</RecordType><CountryLevel>A</CountryLevel><ProcessedBy>USA</ProcessedBy><MatchScore>0</MatchScore><AddressLine1>1825 Kramer Ln</AddressLine1><City>Austin</City><StateProvince>TX</StateProvince><PostalCode>78758-4260</PostalCode><PostalCode.Base>78758</PostalCode.Base><PostalCode.AddOn>4260</PostalCode.AddOn><Country>United States Of America</Country><user_fields/></Address></output_port></xml.ValidateAddressResponse>
<xml.ValidateAddressResponse xmlns="http://www.pb.com/spectrum/services/ValidateAddress"><output_port><Address><Confidence>82</Confidence><RecordType>Normal</RecordType><CountryLevel>A</CountryLevel><ProcessedBy>USA</ProcessedBy><MatchScore>0</MatchScore><AddressLine1>1825 Kramer Ln</AddressLine1><City>Austin</City><StateProvince>TX</StateProvince><PostalCode>78758-4260</PostalCode><PostalCode.Base>78758</PostalCode.Base><PostalCode.AddOn>4260</PostalCode.AddOn><Country>United States Of America</Country><user_fields/></Address></output_port></xml.ValidateAddressResponse>
請指引我在這種情況下。
那麼你試過什麼?你準確地粘在哪裏?堆棧溢出不是免費程序員出租的網站。 – Carpetsmoker
我試圖合併文件中的整個消息並使用下面的兩個命令將它們轉換爲單行。兩者都給出相同的輸出 1)cat file.txt | tr -d「\ t \ n \ r」 2)perl -pe's/\ s + // g'file.txt 但是之後我想根據搜索字符串將單行分成多行單詞''和輸出應該如前所述。 –