Page 1 of 1

Insert 2 lines after every 5th occurence of string

Posted: Mon Nov 28, 2016 3:57 am
by steve1040
I have a text file with 15000 rows (See sample below)

How can I insert 2 lines after every 5th instance of the word "ENTER"

I need to insert the a new line with the word "ENTER" and a second line with the string "DELAY 35000"

Thanks

  • DELAY 5000
    CODE: 1234
    ENTER
    DELAY 500
    CODE: 0000
    ENTER
    DELAY 500
    CODE: 1111
    ENTER
    DELAY 500
    CODE: 2580
    ENTER
    DELAY 500
    CODE: 1212
    ENTER
    DELAY 500
    CODE: 5555
    ENTER
    DELAY 500
    CODE: 2222
    ENTER
    DELAY 5000
    CODE: 1234
    ENTER
    DELAY 500
    CODE: 0000
    ENTER
    DELAY 500
    CODE: 1111
    ENTER
    DELAY 500
    CODE: 2580
    ENTER
    DELAY 500
    CODE: 1212
    ENTER
    DELAY 500
    CODE: 5555
    ENTER
    DELAY 500
    CODE: 2222
    ENTER

Posted: Mon Nov 28, 2016 8:01 am
by ben_josephs
Search | Replace... (<F8>):
Find what: ([\s\S]*?ENTER){5}
Replace with: $0\nENTER\nDELAY 35000

[X] Regular expression

Replace All
Note: [\s\S] matches any character that is white space or is not white space, that is, any character at all, including a newline (which . does not match).