topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 9:27 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #25 on: March 04, 2017, 06:02 AM »
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.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #26 on: March 04, 2017, 06:08 AM »
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:

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #27 on: July 24, 2017, 06: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
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #28 on: July 25, 2017, 02: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

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,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #29 on: August 02, 2017, 12: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,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #30 on: August 02, 2017, 01:07 PM »
That stil doesn't answer the question... :'(

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #31 on: August 02, 2017, 02: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,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #32 on: August 09, 2017, 05:13 AM »
What can we do now ?
The post is opened but not working !!!!!!

 :-[

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #33 on: August 09, 2017, 05: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.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #34 on: September 04, 2017, 03: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,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #35 on: September 05, 2017, 12: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.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #36 on: September 07, 2017, 03: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,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #37 on: September 07, 2017, 03: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?

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #38 on: September 07, 2017, 09:26 PM »
Perhaps an example would better explain the question?

Input text:
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):
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):
Phrase 2.
Phrase 3.
Phrase 6.
Phrase 7.

Which is the preferred output option, 1 or 2?

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #39 on: September 10, 2017, 07:28 AM »
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,940
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #40 on: September 10, 2017, 07:30 AM »
Perhaps an example would better explain the question?

Input text:
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):
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):
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,629
    • View Profile
    • Donate to Member
Re: Manipulate lines in a txt file
« Reply #41 on: September 10, 2017, 01: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.
« Last Edit: September 10, 2017, 01:43 PM by Ath »