I have been researching how to write this bat file I need - and I have come to a dead end. Not sure what is going wrong.
The problem/goal: I have huge txt files I must parse 5 key values from. The first 195 lines of each text file is essentially garbage I am not interested in.
There are 5 text files, 1 each resides in 5 sub-directories. The goal is to write those 5 key values (tokens 7, 11, 19, 21 and 25) into a csv file. (there are 1800 of each of the 5 key values, per text file - making a total of 9000 lines for the csv file I create)
The code I've written fails when entering the first for loop, stating "do( was unexpected at this time"
This is my first time writing functions into a bat file, or requiring more than 1 for loop. I have tweaked my syntax in multiple places, but still get the same error. Obviously I am missing something, but I am not sure what. There may also be additional errors I am not yet aware of, since I can't even get into my first loop.
Code:
@ECHO OFF
setlocal enabledelayedexpansion
set fileout="C:\ffmpeg\fit.csv"
for /R %%f in (*.txt) do (
set THEFILE=%%f
call :setTokens
goto TheEnd
)
:setTokens
for /F "skip=195 tokens=* delims=" %%A in ('%THEFILE%') do(
set the_line=%%A
call :process_line
)
:process_line
for /F "tokens=7,11,19,21,25 delims= =:" %%a in ('%the_line%') do (
set qp=%%a
set slice=%%b
set skip=%%c
set size=%%d
set y=%%e
set OUTLINE=%qp%,",",%slice%,",",%skip%,",",%size%,",",%y%
echo %OUTLINE%>>%fileout%
)
:TheEnd
qpetc within the loop, you need to extract the value using!qp!(as you have invoked delayedexpansion) -%qp%will give you the variable's value at parse time. This is assuming you've invoked aschipfl's change, and note JosefZ's advice that since you are not manipulating the values that you assign toqp, then you can use the rawmetavariables%%a..%%e