Sed XMLレスポンダ

Sed XMLレスポンダ

test.xml私のファイルにはこのXMLレスポンダがあります。

<ingressAnnotations>nginx.ingress.kubernetes.io/server-snippet: |
  location @custom_503 {
    return 503 &quot;&lt;html&gt; &lt;head&gt; &lt;meta http-equiv=&apos;Content-Type&apos; content=&apos;text/html; charset=UTF-8&apos;&gt; &lt;style&gt;...&lt;/style&gt;&lt;/head&gt; &lt;body&gt;&lt;img src=&apos;https://www.jenkins.io/images/logos/jenkins-is-the-way/j
enkins-is-the-way.png&apos; width=&apos;200&apos; height=&apos;200&apos; style=&apos;display: block; margin-left: auto; margin-right: auto;&apos; alt=&apos;jenkins&apos;&gt;&lt;center&gt;&lt;h2&gt;Jenkins is sleeping, please go to jenkins.betclic.net and click your Maste
r link to wake him up. It will be available in a few minutes. This is the wait !!!&lt;/h2&gt;&lt;/center&gt;&lt;/body&gt;&lt;/html&gt;&quot;;
  }
  error_page 503 @custom_503;</ingressAnnotations>

ファイルを解析して内容を削除する必要があります。このような:

<ingressAnnotations></ingressAnnotations>

sedでどうすればいいですか?私はこれを試しています:

sed -i 's/<ingressAnnotations>*<\/ingressAnnotations>/<ingressAnnotations><\/ingressAnnotations>/g' test.xml

しかし、動作しません!

ベストアンサー1

XMLパーサーを使用してファイルを解析および編集できます。このコマンドは、<ingressAnnonations/>文書のどこからでもタグと一致し、その内容をすべて削除します。

xmlstarlet edit --update '//ingressAnnotations' --value '' test.xml

出力

<?xml version="1.0"?>
<ingressAnnotations/>

変換が期待どおりに機能すると確信している場合は、パラメータ--inplace(ファイルを編集できる場所など)が含まれます。xmlstarlet edit --inplace --update …

おすすめ記事