Page 1 of 1

delete previous and 3 following lines

Posted: Thu Jul 16, 2009 9:28 am
by osiftp
Hello,

I have a file of about 40000 lines, it is composed of a blank line than 5 lines of text than a blank line and 5 lines..... always the same pattern.
In the second line of text, I need to locate a string of characters ( always the same ), if found I need to delete the line, the previous line and the next 3 ones. Is there a way to delete the Previous line ?

pattern as follows:

blank line
line1 hgtrefde hrterfde uyhrfrsg yrhtgreerdefd yrhgfd
line2 ujyhg rtgfr rtgf ABCDEF tyhrtgfer ythgf utyhg
line3 uythrgf yhtrgd grezrrzg ryrthg terg 'ehg tregf rer
line4 ythrtgrteg vfc rtg teg trg rteg rtg
blank line
If I find ABCDEF in line2 I need to delete line1/line2/line3/line4
otherwise do nothing

Thank you for your help

Posted: Thu Jul 16, 2009 11:16 am
by ben_josephs
Your description is inconsistent with your example. Assuming the description is correct:
Find what: ^\n.+\n.*ABCDEF.*\n.+\n.+\n.+\n
Replace with: \n

[X] Regular expression

Replace All

Posted: Thu Jul 16, 2009 11:47 am
by osiftp
great, this is what I was looking for.

Thank you for the quick answer.