次のコマンドを実行しようとしています。
sed -i.bak -e "/world/{n;s/hello/hi/g;}" check.txt
check.txtの内容:
hello world
hello world
hello at the last line world
hello world 1!!
受け取った結果は次のとおりです。
hello world
hi world
hello at the last line world
hi world 1!!
誰かがこれを説明できますか?
ベストアンサー1
中かっこはコマンドのグループ化にのみ使用されるため、全体の内容は次のとおりです。
/world/{ ... } - on lines matching /world/, do the commands within {}
n - load next line (and print the current)
s/hello/hi/g - substitute 'hi' for 'hello' on the _currently loaded_ line
つまり、withラインの後にあるラインhello
に変更されます(ただし、交換が行われたラインは確認しません。)hi
world
world