how to read from a txt file and process then write into a txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

how to read from a txt file and process then write into a txt file

#1 Post by goodywp » 26 Jan 2018 15:45

Hi
I have a txt file usually with 3 lines, either line 2 or line 3 could show "ECHO is off." like below:

T501-08680-0102
ECHO is off.
ECHO is off.

I would like to have a output txt file showing as below:

T501-08680-0102
no_sl
no_fk

Thanks
Last edited by goodywp on 26 Jan 2018 15:47, edited 1 time in total.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to read and process then write into a txt file from a text file with some strings

#2 Post by Squashman » 26 Jan 2018 15:47

I guess I would go back and look at the code that was creating that file and figure out what is coded incorrectly, that is causing ECHO OFF to get output to your file.

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: how to read and process then write into a txt file from a text file with some strings

#3 Post by goodywp » 26 Jan 2018 15:51

Squashman wrote:
26 Jan 2018 15:47
I guess I would go back and look at the code that was creating that file and figure out what is coded incorrectly, that is causing ECHO OFF to get output to your file.
Actually, it is due to some lines (variable) empty, originally I added into the source file. but as requirement, it is better hidden inside the code rather exposure outside
So it is correct. whenever the second or third line empty will show ECHO IS OFF.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: how to read from a txt file and process then write into a txt file

#4 Post by Squashman » 26 Jan 2018 16:45

So what is stopping you from using a FOR /F command to read the file. Then use the IF command to see if the line equals what you are checking. Then do something based on that statement being TRUE.

You have been shown all of this in your previous questions over the past 6 months.

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

Re: how to read from a txt file and process then write into a txt file

#5 Post by goodywp » 27 Jan 2018 07:13

Squashman wrote:
26 Jan 2018 16:45
So what is stopping you from using a FOR /F command to read the file. Then use the IF command to see if the line equals what you are checking. Then do something based on that statement being TRUE.

You have been shown all of this in your previous questions over the past 6 months.
Could you please remove this post?
I had a work around to solve this issue. And I might share the issue later ....
Thanks

Post Reply