如何使用awk或sed將以下XML標記轉換爲帶管道分隔文件的文本。 我嘗試了下面的awk,但它沒有從Content type標籤返回全文。任何幫助都會很棒。使用awk或sed將XML轉換爲PIPE分隔的輸出文件
Input_file.dat
<entry>
<updated>2014-05-17T16:34:00-07:00</updated>
<id>994568497</id>
<title>No longer usable</title>
<content type="text">I happen to like the new look, but it crashes with each attempt to use it to perform any real action. Fix it quickly please!.</content>
<im:contentType term="Application" label="Application"/>
<im:voteSum>0</im:voteSum>
<im:voteCount>0</im:voteCount>
<im:rating>1</im:rating>
<im:version>4.2.0.165</im:version>
<author><name>Arcdouble</name><uri>https://test.com/us/reviews/id199894255</uri></author>
</entry>
預計output_file.csv格式
|2014-05-17T16:34:00-07:00|994568497|No longer usable|I happen to like the new look, but it crashes with each attempt to use it to perform any real action. Fix it quickly please!.|1|Arcdouble|https://test.com/us/reviews/id199894255|
你不得不與像XSLT或至少一個XML解析器更好的運氣,比如Python自帶比使用awk或sed的ElementTree的模塊。它們分別用於處理記錄(組織的信息領域)或行,而不是像XML中那樣的分層結構。 –
是的,沒錯,但我正在嘗試使用bash腳本,並嘗試使用以下命令返回值,但有一段時間它會截斷文本消息。 'awk -F'[<>]''{ORS =「|」}; \ /「output_file.csv」}; \ /「output_file.csv」}; \ /「output_file.csv」}; \ />「output_file.csv」}'Input_file.dat' –
user3347931
請使用適當的xml解析器,可以使用任何語言的許多好的解析器。 –