Thank you for the working examples! Great to check the time differences on whatever system you're running on.
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.
Conditional Actions Using Data From Text File
Moderator: DosItHelp
Re: Conditional Actions Using Data From Text File
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.
Re: Conditional Actions Using Data From Text File
Yep, which makes a lot of sense.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.
Re: Conditional Actions Using Data From Text File
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
- 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
Re: Conditional Actions Using Data From Text File
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
FILE TYPE 2
FILE TYPE 3
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:
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.
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
Any assistance appreciated. I think I'm close but just need a little help.
Re: Conditional Actions Using Data From Text File
Using did fix it.
Code: Select all
set /p ln=<%%i