Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 837

Answer by Kamil Maciorowski for Using sed to replace line by dynamic result

$
0
0
<input_file sed '/^SINGLEMEMBERNUMBER: [0123456789]*$/ {   N; s/\([0123456789]*\)\nORDERNUMBER:0$/\1\nORDERNUMBER:\1/;}'

For a line matching ^SINGLEMEMBERNUMBER: [0123456789]*$ (where ^ and $ are anchors for the beginning and the end of pattern space, respectively) we append the Next line of input into the pattern space and then substitution works on the pattern space containing the two lines, so it's possible to do what you want.

We replace \([0123456789]*\)\nORDERNUMBER:0$ with \1\nORDERNUMBER:\1.

\n means a newline character. \1 inside the replacement string gets substituted with what the content of the first pair of parentheses matches. In our case it's what [0123456789]* matches immediately before \nORDERNUMBER:0.


Viewing all articles
Browse latest Browse all 837

Trending Articles