I am trying to remove two lines on one side of the pattern matching from a file full of transactions. I.e. find the match, then delete two lines in front of it, then delete two lines on it and then delete the match. Write this back to the source file.
So the input
D28/10/2011
T-3.48
PINITIAL BALANCE
M
^
and my pattern
sed -i '/PINITIAL BALANCE/,+2d' test.txt
However, this is only deleting two lines after a pattern match, and then removing the pattern match. I can’t work out a logical way to remove all 5 lines of data from the source file using sed.
source
share