私のファイルの内容は次のとおりで、目的の出力を以下に示します。個別のsedコマンドを使用して、ファイルの内容を変更できます。言う
sed -i -e 's!<tag1>FIELD1</tag1>!<tag1>Replaced contents of field1</tag1>! filename
しかし、これらの個々のコマンドを単一のsedスクリプトファイルに置き換えるのに苦労しています。
This is a sample file containing a few tags
<tag1>FIELD1</tag1>
<tag2>FIELD2</tag2>
<tag1>FIELD1 Do not change me</tag1>
<tag2>FIELD2 Do not change me</tag2>
<tag1>FIELD1 Do not change me</tag1>
<tag2>FIELD2 Do not change me</tag2>
必要な出力は
This is a sample file containing a few tags
<tag1>Replaced contents of field1</tag1>
<tag2>Replaced contents of field2</tag2>
<tag2>Some addition to field2</tag2>
<tag1>FIELD1 Do not change me</tag1>
<tag2>FIELD2 Do not change me</tag2>
<tag1>FIELD1 Do not change me</tag1>
<tag2>FIELD2 Do not change me</tag2>