如何提取unix中两个标记之间的值
问题描述:
<trans-unit id="OText.Meetwithcustomer">
<source>Meet with customer</source>
<target>\u015eedin\u0163\u0103 cu clientul
</target>
<note>A step in the sales stage of type qualification in a bid and in a project.</note>
<note>ID:240645::TYPE:Text/Data</note>
</trans-unit>
<trans-unit id="OText.Negotiate">
<source>Negotiate</source>
<target>Negociere</target>
<note>A step in the sales stage of type closed in a standard and in a project.</note>
<note>ID:240646::TYPE:Text/Data</note>
</trans-unit>
我正在将trans-unit id传递给脚本,并且在脚本内部,我试图获取该trans-unit id的目标标记值。 trans-unit id值可以是OText.Meetwithcustomer或OText.Negotiate。如果是OText.Meetwithcustomer,则需要获取值\ u015eedin \ u0163 \ u0103 cu clientul,如果是OText.Negotiate,则需要获取Negociere。如何提取unix中两个标记之间的值
如何在脚本文件中执行此操作。我正在寻找一个使用sed/awk/grep的答案感谢您的帮助。
答
非健壮awk
破解
$ awk -v RS="</trans-unit>" '/OText.Meetwithcustomer/' file
| awk -v FS="<target>" 'NF>1{print $2}'
\u015eedin\u0163\u0103 cu clientul
说明:基于XML结构提取与搜索词的记录。再次从该记录中捕获目标标签旁边的文本。你可以合并脚本,但我认为这样更好。
您的示例与您的陈述相矛盾' Negociere ' –
karakfa
我将传递单元ID传递给脚本,并在脚本内部,我试图获取该传输单元ID的目标标记值。 trans-unit id值可以是OText.Meetwithcustomer或OText.Negotiate。如果是OText.Meetwithcustomer,则需要获取值\ u015eedin \ u0163 \ u0103 cu clientul,如果是OText.Negotiate,则需要获取Negociere。 – arun
[从简单的XML文件中提取数据]的可能的副本(http://*.com/questions/2222150/extraction-of-data-from-a-simple-xml-file) – tripleee