1

I'd like to edit multiple (~2000) txt files in Notepad ++. To be more specific: I'd like to narrow the entire text of into a column with newlines.

Like so:

enter image description here

into:

enter image description here

Of course it is not as simple, because the Text is dynamic and contains brackets for certain terms that will later help a search engine (Those will however not become unfunctional when separated with a newline which comes in very handy).

I found out that I can do so easily with the Line Operation "Split Line" in the "Edit" tab. Now I just need to do it with the rest of the files. I wonder if that can be automated? As it is not a macro it could be kind of tricky. Another thing I thought of was using a RegEx in the "Find in Files" option. Something like "find n characters with n spaces in between them" then "replace the exact same chars with the same chars but add a newline at the end". Or "make a newline every 7 spaces". Not sure if that is a viable approach, though. Im curious about what you think about this. Any Suggestions?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
user80407
  • 117
  • 1
  • 7

1 Answers1

0

In Find in Files, you may use

Find What: (?:^|\G)(\S*(?:\h+\S+){7})\h*
Replace With: $1\n

Do not forget to check the Regular expression radio button at the bottom.

Pattern details:

  • (?:^|\G) - either start of line or the end of the last successful match
  • (\S*(?:\h+\S+){7}) - Group 1 later referenced to with $1 backreference in the replacement pattern, capturing 0+ non-whitespace symbols, followed with exactly 7 sequences of 1+ horizontal whitespaces and 1+ non-whitespaces
  • \h* - zero or more horizontal whitespaces

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Some feedback on further usage: I did some test runs and it seems to have worked, but; I opened the files in Notepad++ and they are as the script formatted them. When I open them in Notepad, they are just normal like they where before! Like the script didn't even happen. Saving them manually, overwriting the file hasn't helped. – user80407 Aug 24 '16 at 23:21
  • In Notepad, CRLF endings are used. Replace with `$1\r\n` to display Windows style line breaks. – Wiktor Stribiżew Aug 24 '16 at 23:23
  • Allright, of course. It displays properly now. All files are in UTF-8, should I use `$1\r\n` or `\n` then? If I want to display it to a user, i guess i should take `$1\r\n` – user80407 Aug 24 '16 at 23:36
  • It does not depend on file encoding, but the tool and OS. In Windows, use `\r\n`, in Unix/Linux, use `\n`, in MacOS use `\r`. Notepad2 and Notepad++ work with any linebreak styles well. – Wiktor Stribiżew Aug 24 '16 at 23:38
  • That is really good to know. For anyone interested, I read more about this [here](http://stackoverflow.com/questions/1552749/difference-between-cr-lf-lf-and-cr-line-break-types). – user80407 Aug 24 '16 at 23:41