ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

[Solved] Manipulate lines in a txt file

<< < (4/9) > >>

Ath:
4 line
Según el autor de este artículo, Kent fue el creador directo de su Repertorio, mientras que sus otros escritos, fueron una recopilación de los apuntes o notas que sus alumnos tomaban durante las clases que él dictaba.

-Contro (February 17, 2017, 02:47 PM)
--- End quote ---
This is not such a good example, as it has only 1 period, so the entire line is removed in step 1...

Ath:
Updated: Don't use PSPad for this operation, as it doesn't have a powerful enough Find & Replace operation, use NotePad++ or EditPad Lite (both free) instead.



Well, I also tried to run this with PSPad, but Find & Replace is quite less powerful than Notepad++ in this area (and even buggy, IMHO).
Open Find & Replace (Ctrl-H)
Regular Expressions needs to be checked, and I chose Direction: Entire scope
Step 1 needs an adjustment:

--- ---Replace: $1Step 2 needs an no adjustment:

--- ---Replace: $1\nStep 3 above can't be performed using PSPad.

Step 4 needs to be added for removing empty lines:

--- ---Choose Edit/Lines manipulation/Remove Blank Lines (Alt-E,N,M)Voila :-\

NB: There are several reasons I dropped PSPad many years ago in favor of Notepad++, this is one of them.
Edit: Do not use PSPad for these operations. Alternatives mentioned.

Ath:
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: \1Press Replace all button

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.":

--- ---(St\.|Dr\.|Mt\.)\n
NB: This won't (can't) work with PSPad! because of the limitations of Find & Replace.
NB2: I haven't found a way to keep the lines with a single period yet, but don't know if that's desired/required?

Also added to the the Notepad++ solution, above.

Ath:
Here's a better, 4 step, solution using NotePad++, realizing that the shortened words really mess up the removal of the 'first phrases' part.

Settings for Replace dialog (Ctrl-H):
Search mode: Regular expression
. matches newline: Off (=not checked)

Step 1: Replace shortened words with an alternative (_ used, assumed not to be anywhere in the document! )

--- ---Find what: (Dr|Mt|St|Lt)\.
Replace with: $1_
Step 2: Remove all first phrases, trim any leading white-space from the remaining part

--- ---Find what: [^\.]*?\.\s*(.*)
Replace with: $1\nPress Replace all button

Step 3: 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\nPress Replace all button

Step 4: Restore periods after all shortened words

--- ---Find what: _
Replace with: .Press Replace all button
Done :D

Contro:
I take all this to home.
The problem is completely solved

Thanks a lot  :tellme:

I have another target.
Opening a new thread !!!!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version