John Amraph
John Amraph

Reputation: 461

Replace text in the line before pattern

I have a text like this

5834589
  MDL-BLABLABLA1
bla-bla2
bla-bla3
bla-bla4
bla-bla5

I want to replace 5834589 (number) in the line before line with the pattern MDL to EXAMPLE-RIVER-5834589 (Just add EXAMPLE-RIVER-).

Any suggestions with sed?

Upvotes: 0

Views: 1286

Answers (1)

potong
potong

Reputation: 58578

This might work for you (GNU sed):

sed '$!N;s/^.*\n.*MDL/EXAMPLE-RIVER-&/;P;D' file

Upvotes: 2

Related Questions