23

How do I add

Keyboard : E : KeyDown
DELAY : 1300
Keyboard : E : KeyUp
DELAY : 200

to every X line in a text document?

3
  • 1
    You can simply do it with a programming language like C or Java. Nov 25, 2013 at 16:01
  • Can you be a little more specific about what your file already contains and what you'd like it to be replaced with? This can probably be done using the find/replace regular expressions feature of Notepad++, but I'd have to get a clearer example (similar to the example here) to provide a solution. Nov 25, 2013 at 16:25
  • FYI you can do it online as well textmechanic.com/text-tools/basic-text-tools/… Mar 14, 2016 at 19:57

3 Answers 3

38

To insert a new line after every 9 rows, go to Search > Replace menu (shortcut CTRL+H) and do the following:

  1. Find what:

    (.*\r?\n){9}\K
    
  2. Replace:

    Your new line\n
    
  3. Select radio button "Regular Expression"

  4. Then press Replace All

You can test it at regex101.

6
  • 3
    This worked for me. But don't forget to uncheck the [x] ". as linebreaks" checkbox for regular search.
    – patrics
    Jan 7, 2016 at 20:21
  • 1
    Worked great, thanks! Note, if your new line has any special regex characters like \ or *, you'll need to escape them with a backslash. \\ or \*. Jan 9, 2017 at 21:37
  • Apperently \K is a little bug for replacing. In my case I needed to use capture groups similar to the other answer instead of using \K.
    – AaronLS
    Feb 1, 2018 at 21:40
  • It works! just noticed that In version v7.9.1 32bit It works if "Search Mode" set to Regular Expression and unchecked ". matches new line" Feb 16, 2021 at 20:41
  • This command seems to work on smaller files, but on some large files (~70,000 lines) it has caused data corruption and then a crash. Jul 22, 2021 at 14:20
4

Still using search/replace, this worked better in my case: selects [your example 9 lines] in one group (the inner '()' pair for each line followed by 'newline'), then the '{}' pair for the look-ahead line count to grab, and the outer '()' pair for the 9 lines retained as a group

((.*\n){9})

Use the \1 variable to restore the same [9] line group, followed by [your sample line insert] and a newline

\1\nKeyboard : E : KeyDown DELAY : 1300 Keyboard : E : KeyUp DELAY : 200\n

2
  • Please read the question again carefully. Your answer does not answer the original question.
    – DavidPostill
    Aug 31, 2016 at 7:20
  • Tweaked to match OP syntax
    – netify
    Oct 19, 2016 at 18:39
0

I'm note sure if it works in Notepad++, but this is how I solved it with PSPads phReplace:

Search:

(.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n.*\r\n)

Replace:

$1New Line[Enter]

[Enter] stands for pressing the Enter-Button as phReplace does not allow \r\n in replace field.

3
  • How is this better than @psxls answer?
    – Toto
    Aug 11, 2019 at 16:35
  • @Toto His answer did not work for me.
    – mgutt
    Aug 11, 2019 at 20:27
  • It is strictly the same but condensed
    – Toto
    Aug 11, 2019 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .