Evan Cutler
asked on
trying to set token read in windows batch to variable.
Greetings,
I have a file that I need to read.
I am using a windows batch to manipulate the file.
my problem is this:
but this:
in the code snippet above, I am trying to use the variable %line% in multiple places. I also need to use a substring of %line% in the first if/then statement, and I've been told you can't substring a %%f output.
Is there something I am missing here?
Thanks Everyone.
I have a file that I need to read.
I am using a windows batch to manipulate the file.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: SET PARAMETER VARIABLES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set BaseDIR="./"
REM set ZIP="test.zip"
set usetext=false
set table=
set line=
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: UNZIP INFADS ZIP FILE TO OBTAIN MANIFAST FILE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM unzip -j %BaseDIR%/%ZIP%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: READ MANIFEST FILE AND CREATE SCHEMA FILES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::rm %BaseDIR%/tablelist.txt
for /f "tokens=* delims=" %%f in (master_index.txt) do (
set line=%%f
echo %line%
if "%line:~0,5%" == "TABLE" (
for /f "tokens=1,2 delims=: " %%a in (%line%) do (
set nulltext=%%a
set usetext=true
set table=%%b
echo record > %BaseDIR%/output/%table%.txt
echo {final_delim=end, record_delim='\n', delim=',', quote=double, padchar='#'} >> %BaseDIR%/output/%table%.txt
echo ( >> %BaseDIR%/output/%table%.txt
)
) else (
if %usetext% == "true" (
for /f "tokens=1,2 delims= " %%a in (%line%) do (
set field=%%a
set datatype=%%b
)
) else (
if "%line%" == "" (
set usetext=false
echo ) >> %BaseDIR%/output/%table%.txt
)
)
)
)
my problem is this:
for /f "tokens=* delims=" %%f in (master_index.txt) do (
set line=%%f
echo %line%
returns: "ECHO is off"but this:
for /f "tokens=* delims=" %%f in (master_index.txt) do (
set line=%%f
echo %%f
returns the value of %%fin the code snippet above, I am trying to use the variable %line% in multiple places. I also need to use a substring of %line% in the first if/then statement, and I've been told you can't substring a %%f output.
Is there something I am missing here?
Thanks Everyone.
ASKER
HI, so I thought the same thing at first,
so I reduced the code:
and I still get the same type of response.
Can you see anything else?
Thanks
so I reduced the code:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: SET PARAMETER VARIABLES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set BaseDIR="./"
REM set ZIP="test.zip"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: SET GLOBAL VALUES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set usetext=false
set table=
set line=
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: UNZIP INFADS ZIP FILE TO OBTAIN MANIFAST FILE
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM unzip -j %BaseDIR%/%ZIP%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: READ MANIFEST FILE AND CREATE SCHEMA FILES
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if EXIST %BaseDIR%/tablelist.txt (
rm %BaseDIR%/tablelist.txt
)
for /f "tokens=* delims=" %%f in (master_index.txt) do (
set list=%%f
echo %list%
)
and I still get the same type of response.
Can you see anything else?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi bp...
Thank you so much,
if I have to reference !list! from that point forward,
how do I do the substring line: if "%line:~0,5%" == "TABLE" (
Thanks
Evan
Thank you so much,
if I have to reference !list! from that point forward,
how do I do the substring line: if "%line:~0,5%" == "TABLE" (
Thanks
Evan
Just use ! Where you would normally use %. Once you are outside the loop you can go back to using % again.
~bp
~bp
As you move your cursor through the code, the editor can colorize the matching parens/brackets.