Hi all,
A bit further down the line have developed the script a bit more and
seems to be working well however when the input file has empty fields
(relatively rare and didnt come up in the test data) there is a double
delimiter which the for loop doesnt seem to pick up as a distinct
token/variable. This causes the following token to input file field
mapping to be one field out. This was predominantly happening for
files with %%i set as "IE" so I made a conditional ordering for that
which seemed to do the trick for that particular issue.
Unfortunately, throwing a few dozen more test files at it revealed
that sometimes other fields were blank too and so I dont think I'm
going to be able to account reliably for the changes through
additional 'else if' code.
The only solution I can think of is a way of getting the for loop to
recognise double vertical bar as a valid field (even if it does get
set as NULL / space or something)
or a way of finding occurrences of "||" and replacing them with "| |"
before using a for loop to interpret the files. Either that or use a
language that lets you more easily reference special characters.
Have considered using a program that I have used before called FART to
get called to replace all instances of || but I'm not sure how to feed
it the character in the first place. I could set some constants to
the find and replace strings but don't seem to be able to.
Any pointers much appreciated!
Please excuse some of the commenting,
@echo off
setlocal enableextensions enabledelayedexpansion
:top
c:
cd c:\nlc\input
for /f "delims=" %%a in ('dir /b /a-d TOY*.txt') do (
for /f "tokens=1-17 delims=|" %%b in ('type "%%a"') do (
REM @echo b %%b c %%c d %%d e %%e f %%f g %%g h %%h i %%i j %%j k %%k
l %%l m %%m n %%n o %%o p %%p q %%q
set TELNO=%%e
if %%i == IE (
@echo %%b^|%%c^|%%c^|%%d^|%%f^|%%g^|^|%%g^|%%h^|%%d^|!TELNO:~5,12!^|
%date:~6,4%^-%date:~3,2%^-%date:~0,2%^|%%p^|1.0^|%%k^|0^| > c:\nlc
\output\%%a
) ELSE (
@echo %%b^|%%c^|%%c^|%%d^|%%f^|%%g^|^|%%g^|%%h^|%%d^|!TELNO:~5,12!^|
%date:~6,4%^-%date:~3,2%^-%date:~0,2%^|%%q^|1.0^|%%l^|0^| > C:\nlc
\output\%%a
)
@echo %%b^|%%c^|%%c^|%%d^|%%f^|%%g^|^|%%g^|%%h^|%%d^|!TELNO:~5,12!^|
%date:~6,4%^-%date:~3,2%^-%date:~0,2%^|%%q^|1.0^|%%l^|0^|
del %%a
)
)
@echo %TIME%
c:\nlc\sleep 1
GOTO top