sed
Opération de branchement
Recherche…
Introduction
L'opération de branchement de sed
peut aider à contrôler le flux du programme.
Ne remplacera-t-il pas l'expression multiple avec une branche inconditionnelle?
Supposons que j'ai un fichier nommé in.txt
:
$ cat in.txt
a
b
a
c
a
d
Je veux seulement remplacer le a\nc
avec deleted
, mais pas a\nb
ou 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
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow