801
Post New Requests Here / Re: Manipulate lines in a txt file
« Last post by Ath on February 17, 2017, 01:39 PM »See below, Reply #18, for a better working, 4 step, solution, using NotePad++
Here's a '3-step' Notepad++ solution:
Settings for Replace dialog (Ctrl-H):
Search mode: Regular expression
. matches newline: Off (=not checked)
Step 1: (Remove all first phrases, trim any leading white-space from the remaining part)
Step 2: (Replace all remaining phrases by the phrase and a new-line, removing any white-space in front of a phrase)
There are other issues with these type of free texts, the (short) example contains shortened words like St. and Dr. that cause excess line-breaks to be inserted. These can be fixed by adding another step to the Notepad++ recipe:
Step 3: (Restore shortened words with their second part)
Done
If more shortened words are found, add them to Find what within the round braces, prefixed with a vertical pipe, like this for adding "Mt.":
Remember: It replaces the file-contents, so either work on a copy or use Save as... if the original file needs to be preserved.
PS: Tested using Notepad++ 7.2.2 and EditPad Lite 7.5
NB: please report how it's working for your file(s) so the thread can be moved to Resolved when satisfactory.
Edit: Updated step 1 to remove leading white-space of the remaining text.
Edit2: Added step 3 to restore 'unintended' line-breaks after shortened words like Dr., St., etc.
Edit2: Replaced \1 substitutions by more generic $1.
Edit2: Also tested with EditPad Lite. PSPad isn't capable of doing step 3, so I'd advise to not use PSPad!
Edit3: Superseded by a better 4 step solution, see below, Reply #18
Here's a '3-step' Notepad++ solution:
Settings for Replace dialog (Ctrl-H):
Search mode: Regular expression
. matches newline: Off (=not checked)
Step 1: (Remove all first phrases, trim any leading white-space from the remaining part)
Find what: [^\.]*?\.\s*(.*)
Replace with: $1\n
Press Replace all buttonReplace with: $1\n
Step 2: (Replace all remaining phrases by the phrase and a new-line, removing any white-space in front of a phrase)
Find what: \s*([^\.]*?\.)
Replace with: $1\n
Press Replace all buttonReplace with: $1\n
There are other issues with these type of free texts, the (short) example contains shortened words like St. and Dr. that cause excess line-breaks to be inserted. These can be fixed by adding another step to the Notepad++ recipe:
Step 3: (Restore shortened words with their second part)
Find what: (St\.|Dr\.)\n
Replace with: $1
Press Replace all buttonReplace with: $1
Done

If more shortened words are found, add them to Find what within the round braces, prefixed with a vertical pipe, like this for adding "Mt.":
Find what: (St\.|Dr\.|Mt\.)\n
Remember: It replaces the file-contents, so either work on a copy or use Save as... if the original file needs to be preserved.
PS: Tested using Notepad++ 7.2.2 and EditPad Lite 7.5
NB: please report how it's working for your file(s) so the thread can be moved to Resolved when satisfactory.
Edit: Updated step 1 to remove leading white-space of the remaining text.
Edit2: Added step 3 to restore 'unintended' line-breaks after shortened words like Dr., St., etc.
Edit2: Replaced \1 substitutions by more generic $1.
Edit2: Also tested with EditPad Lite. PSPad isn't capable of doing step 3, so I'd advise to not use PSPad!
Edit3: Superseded by a better 4 step solution, see below, Reply #18

Recent Posts


)

the old one was old (2012) and slow, and now all is fine.

