Zoeken…


Invoering

De vertakkende werking van sed kan helpen de stroom van het programma te regelen.

Voer regexp met meerdere regels uit door onvoorwaardelijke vertakking

Stel dat ik een bestand heb met de naam in.txt :

$ cat in.txt
a
b
a
c
a
d

Ik wil alleen de a\nc door deleted , maar niet a\nb of 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
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow