我有curl的以下输出:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'><env:Header></env:Header><env:Body><ns3:getNodesResponse xmlns:ns3='http://node.sdk.nms.ov.hp.com/'><return><item><created>2016-01-12T18:04:44.617Z</created><deviceCategory>com.hp.ov.nms.devices.other</deviceCategory><deviceDescription>No Device Profile found for this device. The assigned SNMP OID is the top of a Opto 22 subtree</deviceDescription><deviceFamily>com.hp.ov.nms.devices.opengear</deviceFamily><deviceModel>Opengear Generic</deviceModel><deviceVendor>com.hp.ov.nms.devices.opengear</deviceVendor><discoveryState>DISCOVERY_COMPLETED</discoveryState><endNode>false</endNode><>false</IPv4Router><id>330742910324</id><lanSwitch>false</><longName>xxxxxxxxxxxxxxxxx</longName><managementMode>MANAGED</managementMode><modified>2016-06-21T19:46:38.837Z</modified><name>xxxxxxxxxxxxxxx</name><notes></notes><snmpSupported>true</snmpSupported><snmpVersion>V2C</snmpVersion><status>NORMAL</status><systemContact>Unspecified (Management Console -> Alerts & Logging -> SNMP)</systemContact><systemDescription>Linux xxxxx 3.10.0-uc0 #1 Mon Dec 21 16:21:01 EST 2015 armv4tl</systemDescription><systemLocation>Unspecified (Management Console -> Alerts & Logging -> SNMP)</systemLocation><systemName>xxxxxx</systemName><systemObjectId>.1.3.6.1.4.1.25049.1.81</systemObjectId><uuid>e3a77c1c-ab82-4dfb-b7bf-78e1dadef888</uuid></item></return></ns3:getNodesResponse></env:Body></env:Envelope>
如何在<id>
和</id>
之间检索文字?我尝试使用:
sed -e 's/<id>\(.*\)<\/id>/\1/'
但这导致整个文本块被打印出来,而不仅仅是&lt; \ id&gt;之间的部分。
我没有能力在这个盒子上安装程序,所以我不想经历手动编译xmlstarlet等的麻烦,只是为了解决这个问题。
答案 0 :(得分:1)
感谢您解释为什么您没有使用正确的工具进行明显的工作
sed -e 's/.*<id>\(.*\)<\/id>.*/\1/'
匹配你不想要的东西(未经测试)