""タグ間のテキストを削除します。ここで、 " "は別の行にあります。

td.txt次の内容を含むテキストファイルがあります。

More here || <--field="data.com":CHK test text--> || test 2 test x @ -- 
||<!-- more data 
here --> ||
echo "||<!--field="data.com":CHK test text-->|| test 2 test x @ -- ||<--field="data.com":CHK more data here -->|| test data

すべてのインスタンスを削除したいです。<!-- and all text inside the tags -->

sedこのような表現があります。cat td.txt | sed 's/<!--[^P]*-->//g'

必要に応じてタグとその内容を削除しますが、<!--タグが1行で始まり別の行で終わる場合は削除されません-->

上記の式を使った結果は

More here || <--field="data.com":CHK test text--> || test 2 test x @ -- 
||<!-- more data 
here --> ||
echo "|||| test data

見せる

<!-- more data 
    here -->

タグがまだ存在しています

<!-- and all text inside the tags -->とのすべてのインスタンスを削除する方法
<!-- and all text
inside the tags -->

sed、grep、または他のツールを使用していますか?

ベストアンサー1

XML文書からコメントを削除するには、次のものを使用できますxmlstarlet

xmlstarlet ed -d '//comment()' file.xml

コメントが複数行にまたがるかどうかは重要ではありません。

このツールはxmlstarlet()オプションによる内部編集をサポートしています。-L--inplace

おすすめ記事