sed
Förgreningsoperation
Sök…
Introduktion
Förgrening av sed
kan hjälpa till att kontrollera flödet av programmet.
Gör reglering av flera linjer med en ovillkorlig gren
Antag att jag har en fil med namnet in.txt
:
$ cat in.txt
a
b
a
c
a
d
Jag vill bara ersätta a\nc
med deleted
, men inte a\nb
eller 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
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow