这是xml-data:
<DATA VERSION="1.0">
<TABLES>
<ITEM>
<identifyer V="1234"></identifyer>
<property1 V="abcde"></property1>
<Property2 V="qwerty"></property2>
</ITEM>
<ITEM>
<identifyer V="5678"></identifyer>
<Property1 V="zyxwv"></property1>
<Property2 V="dvorak"></property2>
</ITEM>
</TABLES>
</DATA>
Run Code Online (Sandbox Code Playgroud)
我试图找到有价值property2的项目.我可以选择数据:identifyer1234
$ xmlstarlet sel -t -c "/DATA/TABLES/ITEM/identifyer [@V=1234]" test.xml
<identifyer V="1234"/>
Run Code Online (Sandbox Code Playgroud)
需要两种类型的输出:
$ xmlstarlet <some magic>
<identifyer V="1234"></identifyer>
<property1 V="abcde"></property1>
<Property2 V="qwerty"></property2>
Run Code Online (Sandbox Code Playgroud)
和:
$ xmlstarlet <some magic>
qwerty
Run Code Online (Sandbox Code Playgroud) 请随意编辑标题,我不知道如何最好地表达它:).
我有JSON,例如,看起来像这样:
{
"things": [
{
"name": "foo",
"params": [
{
"type": "t1",
"key": "key1",
"value": "val1"
},
{
"type": "t1",
"key": "category",
"value": "thefoocategory"
}
]
},
{
"name": "bar",
"params": [
{
"type": "t1",
"key": "key1",
"value": "val1"
},
{
"type": "t1",
"key": "category",
"value": "thebarcategory"
}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的是输出看起来像
[
{
name: "foo",
category: "thefoocategory"
},
{
name: "bar",
category: "thebarcategory"
}
]
Run Code Online (Sandbox Code Playgroud)
我能够很容易地提取名称 jq ' .things | .[] | .name'
我也可以提取类别 jq ' .things …