
私は、これらの両方のコマンドを組み合わせたエレガントなソリューションを探しています:
sed -i '/Y/! s/replace/with/' /path/to/file
sed -i '/X/ s/replace/with/' /path/to/file
私は試した
sed -i '/X/ /Y/! s/replace/with/' /path/to/file
動作しません。これに対するエレガントな解決策はありますか?
答え1
たぶんこんな感じでしょうsed '/X/ {/Y/! s/replace/with/}'
か?
$ sed '/X/ {/Y/! s/replace/with/}' << EOF
X replace X
X replace Y
Y replace X
Y replace Y
EOF
X with X
X replace Y
Y replace X
Y replace Y