Link to home
Start Free TrialLog in
Avatar of Evan Cutler
Evan CutlerFlag for United States of America

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.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 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
			)
		)
	)
)

Open in new window


my problem is this:
for /f "tokens=* delims=" %%f in (master_index.txt) do (
	set line=%%f
	echo %line%

Open in new window

returns: "ECHO is off"

but this:
for /f "tokens=* delims=" %%f in (master_index.txt) do (
	set line=%%f
	echo %%f

Open in new window

returns the value of %%f

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.
Avatar of ThomasMcA2
ThomasMcA2

To start with, try fixing your parenthesis. See attached screen shot. If you use a programming editor like Notepad++, the syntax highlighting (colors) make it a lot easier to recognize problems.

User generated image
As you move your cursor through the code, the editor can colorize the matching parens/brackets.
Avatar of Evan Cutler

ASKER

HI, so I thought the same thing at first,
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%
)

Open in new window


and I still get the same type of response.
Can you see anything else?
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Just use ! Where you would normally use %. Once you are outside the loop you can go back to using % again.

~bp