I'm trying to filter this code for the data between <cookie>
& </cookie>
and the data between account-id="
& "
(the trailing quote)
<?xml version="1.0" encoding="utf-8"?>
<results>
<status code="ok"/>
<common locale="en" time-zone-id="85">
<cookie>na3breezfxm5hk6co2kfzuxq</cookie>
<date>2012-11-11T16:26:52.713+00:00</date>
<host>http://meet97263421.adobeconnect.com</host>
<local-host>pacna3app09</local-host>
<admin-host>na3cps.adobeconnect.com</admin-host>
<url>/api/xml?action=common-info</url>
<version>8.2.2.0</version>
<tos-version>7.5</tos-version>
<product-notification>true</product-notification>
<account account-id="1013353222"/>
<user-agent>curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5</user-agent>
</common>
</results>
Any help would be appreciated.
EDIT
This is the curl command I run to return the above xml.
curl -s http://meet97263421.adobeconnect.com/api/xml?action=common-info
In general, regexes (and therefore grep
) aren't well-suited to parsing XML, but if you can guarantee the input is well-formatted and consistent you can do this most easily with grep
's perl-style regexes (on systems whose grep has them):
grep -oP '(?<=<cookie>).*?(?=</cookie>)'
grep -oP '(?<=account-id=").*?(?=")'
If you want them in the same command, you can separate them with a |
, but then you have to tell which matches which.
grep -oP '(?<=<cookie>).*?(?=</cookie>)|(?<=account-id=").*?(?=")'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With