test.xml
私のファイルにはこのXMLレスポンダがあります。
<ingressAnnotations>nginx.ingress.kubernetes.io/server-snippet: |
location @custom_503 {
return 503 "<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> <style>...</style></head> <body><img src='https://www.jenkins.io/images/logos/jenkins-is-the-way/j
enkins-is-the-way.png' width='200' height='200' style='display: block; margin-left: auto; margin-right: auto;' alt='jenkins'><center><h2>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 !!!</h2></center></body></html>";
}
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 …