I guess I'm mad enough to use a batch file, in the first place, but this problem has me tearing my hair out! The below batch script usually works just fine. However, on first run it will give a "The syntax of the command is incorrect" error; and it will do this until I REM
out everything, run it through, and then unREM
it. Then it magically starts working again!
@echo off
REM Create processed data directory
set "PROCDIR=processed"
mkdir %PROCDIR% 2>nul
REM Loop through CSV files and process them
for %%f in (*.csv) do (
set "in=%%~nf"
set "input=%%~nxf"
set "out_lang=%PROCDIR%\%in%_lang.csv"
set "out_spr=%PROCDIR%\%in%_spr.csv"
set "out_ajt=%PROCDIR%\%in%_ajt.csv"
echo Processing %input%
REM Split input file appropriately
REM FIXME Hardcoded line ranges are brittle
sed -n "1,2p" %input% > %out_lang%
sed -n "3,55p" %input% > %out_spr%.tmp
sed -n "56,$p" %input% > %out_ajt%.tmp
REM Unpack SPR data
REM n.b., Needs gawk 4, or later
gawk -f spr.awk %out_spr%.tmp > %out_spr%
del %out_spr%.tmp
REM Substitute AJT data values
REM n.b., -i seems to be buggy in Windows
sed -f ajt.sed %out_ajt%.tmp > %out_ajt%
del %out_ajt%.tmp
)
If I REM
out the @echo off
, it appears it's failing because the variable substitution sometimes -- for unknown reasons -- doesn't work. Then, when it gets to sed
, it just gives up.
I assume I'm missing something... Any ideas what it might be!? (Besides my marbles!)