Link to home
Start Free TrialLog in
Avatar of Bryan Rod
Bryan Rod

asked on

Find Error Codes in .TXT file

I need a batch script for windows that does the following:

Scan *.txt file in the “ARAT_Preverification” folder to find if there are any “Error codes” like 501, 502, 503 - 509 (scenario mentioned below);

Below is the sample .txt file where every 1st row has no data and can be ignored; the following rows has data where the batch should scan and find the error codes (if any) between 18-20 characters only, each row has 90 characters including spaces. The row starts with Letter D in each file except the first row.

H0001200008143800120918155209
D43442371013477773520000001280012091800001
D43442371011722225010000000900012091800001
D43442371007692925040000007200012091800001

If any *.txt file has the above-mentioned error codes then that file should be moved to “ARAT_Verified” Folder.

I got the below code it works sometime if the file is small, if the file size is large (over 1000 rows) it doesn't detect the error code, anything wrong with he code?

@echo off
setlocal enabledelayedexpansion
for %%x in (D:\ARAT\ARAT_Preverification\*.txt) do (
set "file=%%x"
for /f %%i in ('type "!file!"') do set "string=%%i"
    set "str=!string:~17,3!"
    for %%a in (501 502 503 504 505 506 507 508 509) do if "!str!"=="%%a" move "!file!" "D:\ARAT\ARAT_Verified"
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial