{"id":1453,"date":"2023-03-23T22:24:36","date_gmt":"2023-03-23T14:24:36","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1453"},"modified":"2023-04-28T20:48:27","modified_gmt":"2023-04-28T12:48:27","slug":"shell-extracts-xml-tag-values-through-sed","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/23\/shell-extracts-xml-tag-values-through-sed\/","title":{"rendered":"shell\u901a\u8fc7sed\u63d0\u53d6xml\u6807\u7b7e\u503c"},"content":{"rendered":"<h2>\u65b9\u6cd5<\/h2>\n<pre><code>$ eureka=`curl $EUREKA_HOST\/eureka\/apps\/$APP_NAME -s`\n$ instanceId=$(sed -n -e &#039;s\/.*&lt;instanceId&gt;\\(.*\\)&lt;\\\/instanceId&gt;.*\/\\1\/p&#039; &lt;&lt;&lt; $eureka)\n$ echo $instanceId<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code>$ eureka=`curl $EUREKA_HOST\/eureka\/apps\/$APP_NAME -s`\n$ echo $eureka | sed &#039;s\/^.*&lt;instanceId&gt;\/\/g&#039;| sed &#039;s\/&lt;\\\/instanceId&gt;.*$\/\/g&#039;<\/code><\/pre>\n<pre><code>$ eureka=`curl $EUREKA_HOST\/eureka\/apps\/$APP_NAME -s`\n$ instanceId=$(grep -oPm1 &quot;(?&lt;=&lt;instanceId&gt;)[^&lt;]+&quot; &lt;&lt;&lt; &quot;$eureka&quot;)\n$ echo $instanceId<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/15849119\/why-does-sed-not-replace-all-occurrences\" title=\"Why does sed not replace all occurrences\">Why does sed not replace all occurrences<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/stackoverflow.com\/questions\/17333755\/extract-xml-value-in-bash-script\" title=\"Extract XML Value in bash script\">Extract XML Value in bash script<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5 $ eureka=`curl $EUREKA_HOST\/eureka\/apps\/$APP_NAME -s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[89],"class_list":["post-1453","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-shell"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1453"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1453\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}