DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Last post Author Topic: [Solved] Manipulate lines in a txt file  (Read 32,213 times)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #25 on: March 04, 2017, 12:02 PM »
Well, an answer still missing is what to do if there is only one (1) phrase on a line. With current scripts the entire line will be deleted.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #26 on: March 04, 2017, 12:08 PM »
I was revising because I don't like forget the thread.
The forum has a 'Mark topic' button with several options to keep topics in sight... :)

Please reply to my previous answer :up:
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #27 on: July 24, 2017, 11:03 PM »
Sorry Ath.
I have to revise this post.
It's too late here now. I must be in bed and rest. I will revise !!!!!!

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 933
    • Participated in NANY Challenge Twice
    • Coding Snacks
Re: Manipulate lines in a txt file
« Reply #28 on: July 25, 2017, 07:13 PM »
:) How about this one?

Fill inn source and target and save the script as Parts.ahk. Download and install Autohotkey to run the script.

Skrommel

Code
source=Source.txt
target=Target.txt

#NoEnv
#SingleInstance,Force
SetBatchLines,-1

string:=""
FileRead,lines,%source%
Loop,Parse,lines,`n                                ; Split by line break
{
  StringSplit,part_,A_LoopField,.                  ; Split by period
  If part_0<3                                      ; 1 part
    line:=A_LoopField
  Else
    StringReplace,line,A_LoopField,%part_1%.,      ; Remove part 1
  line=%line%                                      ; Remove trailing space
  string.=line "`n"                                ; Add line break
}
FileDelete,%target%
FileAppend,%string%,%target%

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #29 on: August 02, 2017, 05:46 PM »
:-*
Well, an answer still missing is what to do if there is only one (1) phrase on a line. With current scripts the entire line will be deleted.
I am going to try the script Skrommel
Where are you Ath ?
;D

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #30 on: August 02, 2017, 06:07 PM »
That stil doesn't answer the question... :'(
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #31 on: August 02, 2017, 07:24 PM »
Difficult question then !!!!!

i don't get any results with the script. I don't know what I am doing wrong.

I don't obtain nothin in the target.txt
I have the script in the desktop and the txt files too.

:-[

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #32 on: August 09, 2017, 10:13 AM »
What can we do now ?
The post is opened but not working !!!!!!

:-[

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #33 on: August 09, 2017, 10:38 AM »
What can we do now ?
The post is opened but not working !!!!!!
Just as has happened before, it is quite difficult to understand what you are saying...

We had come to a working solution (post #18 in this thread, accepted by you in post #19), with only 1 question remaining:
- What should happen if a line in the file has only 1 period in it. Should that line be removed, or should it remain in the output?

Until this question is answered (I have asked 4 times before for an answer on this, this is the 5th and last time), any other questions (or solutions) here should be postponed, IMHO.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #34 on: September 04, 2017, 08:27 PM »
What can we do now ?
The post is opened but not working !!!!!!
Just as has happened before, it is quite difficult to understand what you are saying...

We had come to a working solution (post #18 in this thread, accepted by you in post #19), with only 1 question remaining:
- What should happen if a line in the file has only 1 period in it. Should that line be removed, or should it remain in the output?

Until this question is answered (I have asked 4 times before for an answer on this, this is the 5th and last time), any other questions (or solutions) here should be postponed, IMHO.
I understand.
Sorry if I cannot do my best.
:tellme:

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #35 on: September 05, 2017, 05:30 PM »
I understand.
Sorry if I cannot do my best.
:tellme:
Well, the only thing we want you to do, in this situation, is to answer the question. Why is that so hard? It's not a difficult question, and only a yes or no answer is enough.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #36 on: September 07, 2017, 08:19 PM »
I am in a difficult situation i am afraid : need more english knowledge.

Please . What is the question exactly i can respond yes or no ?

Best Regards
:-[

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #37 on: September 07, 2017, 08:22 PM »
Please . What is the question exactly i can respond yes or no ?

- What should happen if a line in the file has only 1 period in it. Should that line be removed, or should it remain in the output?
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: Manipulate lines in a txt file
« Reply #38 on: September 08, 2017, 02:26 AM »
Perhaps an example would better explain the question?

Input text:
Code
Phrase 1. Phrase 2. Phrase 3.
Phrase 4.
Phrase 5. Phrase 6. Phrase 7.

Output Option 1 (Phrase 4 remains since it is the only Phrase in the line):
Code
Phrase 2.
Phrase 3.
Phrase 4.
Phrase 6.
Phrase 7.

Output Option 2 (Phrase 4 is removed because it is the first Phrase in the line):
Code
Phrase 2.
Phrase 3.
Phrase 6.
Phrase 7.

Which is the preferred output option, 1 or 2?
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #39 on: September 10, 2017, 12:28 PM »
Please . What is the question exactly i can respond yes or no ?

- What should happen if a line in the file has only 1 period in it. Should that line be removed, or should it remain in the output?
That line must be removed


:-*.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,947
Re: Manipulate lines in a txt file
« Reply #40 on: September 10, 2017, 12:30 PM »
Perhaps an example would better explain the question?

Input text:
Code
Phrase 1. Phrase 2. Phrase 3.
Phrase 4.
Phrase 5. Phrase 6. Phrase 7.

Output Option 1 (Phrase 4 remains since it is the only Phrase in the line):
Code
Phrase 2.
Phrase 3.
Phrase 4.
Phrase 6.
Phrase 7.

Output Option 2 (Phrase 4 is removed because it is the first Phrase in the line):
Code
Phrase 2.
Phrase 3.
Phrase 6.
Phrase 7.

Which is the preferred output option, 1 or 2?

The phrase 4 must be removed.
I have assumed that the input text is the result of the first process of the phrases.
So I have control of that phrase and I don't need that phrase anymore.

When a line have only one phrase we can remove that line because I have processed that phrase previously.

Best Regards


Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,649
    • Participated in NANY Challenge Eleven Times
    • Coding Snacks
    • Linux User
    • Hardware Hacker
Re: Manipulate lines in a txt file
« Reply #41 on: September 10, 2017, 06:37 PM »
Aha, so then my solution using notepad++ in post #18 or skrommel's ahk-script in post #28 should both work for you. No changes needed. Thanks for clearing that up.

Moderators, please move this thread to the 'resolved' section.
/Ton
Ath's software collection, Quote: "A problem well stated is a problem half-solved." (Charles Kettering)
« Last Edit: September 10, 2017, 06:43 PM by Ath »

Original address: https://www.donationcoder.com/forum/index.php?topic=43524.0