USING BATCH/BASH On Windows: I'm wondering how to search a text file (.txt) line by line as each line is its own string, look for the location directory (e.g, C:...) which is part of this string. and just take out that specific part and store in a variable.
This is to be done for each line though.
Any help would be appreciated.
TestRecID TestUserID 5 2017-04-20 TestTAtRec No 2.560 No C:\Test1\Test3 Tester
TestRecID TestUserID 5 2017-04-20 TestTAtRec No 2.560 No C:\Test2\Test2 Tester
TestRecID TestUserID 5 2017-04-20 TestTAtRec No 2.560 No C:\Test3\Test1 Tester
Presume that the above are each row in the text file. At each space in the line that is where the different columns would have been in the DB.
The Expected Result would be to have:
C:\Test1\Test3 --> Variable 1
C:\Test2\Test2 --> Variable 2
C:\Test3\Test1 --> Variable n
Stored in some variable.
I really can't overstate enough how much of a newb I am with Batch/Bash for Windows
Follow Up Question:
for /f "tokens=9 delims= " %%a in (%findfile%) do echo %%a
I want to then store the %%a in a variable_name
I thought it would be a case of:
for /f "tokens=9 delims= " %%a in (%findfile%) do echo %%a
set variable_name = %%a
But it is not working??
Was Answered but I got given out to for asking a question in an answer,
The Answer given:
for /f "tokens=9 delims= " %%b in (%findfile%) do set "location=%%b"
EDIT Working Loop for taking unique variables (Thanks to @Stephen):
REM Get Locations from textfile:
for /f "skip=1 tokens=9 delims= " %%a in (%findfile%) do set "_%%a=yes"
REM Translate into proper variables:
set count = 0
for /f "tokens=1* delims==#" %%a in ('set _') do (
set /a count+=1
set _location[%count%]=%%a
)
set _location
This is the FFMPEG function I'm using but I now need it to take in each variable separately:
for %%i in (%_location%\*.mp4) do (if not exist "%%~ni\" MD "%%~ni"
ffmpeg -i "%%i" -vframes 1 -f image2 -start_number 0 "%%~ni\%%~ni_Summary_%%3d.jpeg"
)
The %_location% part in the function above is where my issue is? of it not taking multiple variables at once