我试图从下面的xml标签中提取和连接<id>
和<name>
的值
<applications><application>
<id>292</id>
<name>Test</name>
<accountGuid>2-b01e-2ef14d11c5e0</accountGuid>
</application>
<application>
<id>195</id>
<name>State</name>
<accountGuid>2-b01e-2ef14d11c5e0</accountGuid>
</application>
<application>
<id>266</id>
<name>Home</name>
<accountGuid>2-b01e-2ef14d11c5e0</accountGuid>
</application>
</applications>
期望输出
292:Test
195:state
266:Home
我使用下面的sed来提取,但是它给我的输出是
sed -n 's:.*<id>(.*)</id>.*:1:p;s:.*<name>(.*)</name>.*:1:p'
292
Test
195
state
266
Home
你们能帮我知道我应该怎么做才能得到想要的输出吗?
With xmlstarlet:
xmlstarlet select --text --template --match "/applications/application" --value-of "concat(id,':',name)" -n file.xml
输出:
<>之前292:测试195:国家266:Home参见:xmlstarlet select --help