Conditional Actions Using Data From Text File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Conditional Actions Using Data From Text File

#16 Post by Samir » 08 Nov 2015 16:25

Thank you for the working examples! Great to check the time differences on whatever system you're running on. 8)

I looked at both lines where I'm calling findstr and unfortunately the lines where the information I need can vary drastically in the file. Sometimes it might be on line 15, but at other times it might be almost the end of the file. Hence why findstr is actually the best tool for the job.

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

Re: Conditional Actions Using Data From Text File

#17 Post by Squashman » 08 Nov 2015 17:09

Ok. So we are just saying that because we know it will always be a specific line number we just force the code to do so.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Conditional Actions Using Data From Text File

#18 Post by Samir » 08 Nov 2015 17:53

Squashman wrote:Ok. So we are just saying that because we know it will always be a specific line number we just force the code to do so.
Yep, which makes a lot of sense. 8)

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Conditional Actions Using Data From Text File

#19 Post by aGerman » 08 Nov 2015 18:54

Er, nope.

- FINDSTR:
It takes always a more or less constant time to load the process but enumerating the lines in the text file is obviously pretty fast.

- FOR /L and SET /P
You don't waste time for loading another process but enumerating the lines is fast but less performant compared with FINDSTR. Also the line length that SET /P is able to read is limitied to (I think) 1021 characters (even if that shouldn't be of much interest in this case).

There is a break even point where you should prefer FINDSTR over SET /P. Certainly you shouldn't try to read the 5,634,987th line of a file using FOR /L and SET /P even if you know the data you need can always be found in line 5,634,987 :wink:

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Conditional Actions Using Data From Text File

#20 Post by Samir » 09 Apr 2017 13:35

So fast forward a few years and format and number of files has changed. Instead of 4, there are now 16. But there has been a change in the format that may make the code simpler. Here's the new format of the files.

FILE TYPE 1

Code: Select all

Credit Batch 029 Summary
MISC
ADDR

Seq#  Account Number          Amount Status
- MORE MISC BELOW THIS LINE -

FILE TYPE 2

Code: Select all

Debit Batch 029 Summary
MISC
ADDR

Seq#  Account Number          Amount Status
- MORE MISC BELOW THIS LINE -

FILE TYPE 3

Code: Select all

EMS Batch 029 Summary
MISC
ADDR
No Data To Report

The first line on file type 3 essentially just changes for 14 of the 16 files. I've already adapted the code for the 'No Data To Report' vs the original 'NO INFORMATION TO REPORT', and that part seems to work.

For file types 1 and 2, Instead of the relevant information being on line 8, it is now on the first line, which should simplify some of the code as only the first line is needing to be read. But I haven't figured out how to modify the code for this. I think the following could replace the for loop that goes through the first 7 lines and the set command on the next line:

Code: Select all

set /p ln=<%%i
but I'm not sure because of the way the variable 'ln' is being used.

Any assistance appreciated. I think I'm close but just need a little help. 8)

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Conditional Actions Using Data From Text File

#21 Post by Samir » 10 Apr 2017 12:27

Using

Code: Select all

set /p ln=<%%i
did fix it.

Post Reply