サーチ…
前書き
sed
の分岐操作は、プログラムの流れを制御するのに役立ちます。
無条件ブランチに置き換えて複数行の正規表現を行う
in.txt
という名前のファイルがあるとします。
$ cat in.txt
a
b
a
c
a
d
私は交換したいa\nc
してdeleted
ではなくa\nb
かa\nd
。
$ sed -e ':loop # create a branch/label named `loop`
$!{
N # append the next line of input into the pattern space
/\n$/!b loop # If it is not the last line go to the `loop` branch again
}
s/a\nc/"deleted"/' in.txt # do replacing in the pattern space
a
b
"deleted" # see! succeed
a
d
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow