TonyC Posted December 13, 2010 Share Posted December 13, 2010 Hi Folks,This is my first post so please forgive me if its too wordy or unclear.I'm trying to create a nested FOR loop in batch (w2003 SE SP2). What I want to do is take all the values in 1 text file and run each of them against each of the values in another text file.The first text file has 1 entry on each line and the second text file has 2 entries which are delimited by a ":" (colon not weird smiley face).The code is below. The echo's I've placed in Italics are just for testing as I want to see if the value has been set as the variable. In both cases the variable isnt being echo'ed.I know that I could just use the %a %i %j rather than Variables but I'd prefer to use the variables as i think its clearer and may need to add further variables.SETLOCAL EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('type WWN.txt') do (Set WWN=%%aEcho WWN is %WWN% for /f "tokens=1-2 delims=:" %%i in ('type DirPort.txt') do ( Set Dir=%%i Set Port=%%j Echo Dir is %Dir% Port is %Port% echo - symmask -sid -wwn %%a -dir %%i -p %%j -noprompt >>WWNDirport.txt )Echo WWN Processed is %WWN% >>WWNDIRPORT.txt)thanks for any feedback Link to comment Share on other sites More sharing options...
Yzöwl Posted December 13, 2010 Share Posted December 13, 2010 What happens if you change it slightly like this?SETLOCAL EnableDelayedExpansionfor /f "tokens=*" %%a in ('type WWN.txt') do ( Set WWN=%%a Echo WWN is !WWN! for /f "tokens=1-2 delims=:" %%i in ('type DirPort.txt') do ( Set Dir=%%i Set Port=%%j Echo Dir is !Dir! Port is !Port! echo - symmask -sid -wwn %%a -dir %%i -p %%j -noprompt >>WWNDirport.txt ) Echo WWN Processed is !WWN! >>WWNDIRPORT.txt ) Link to comment Share on other sites More sharing options...
TonyC Posted December 13, 2010 Author Share Posted December 13, 2010 What happens if you change it slightly like this?SETLOCAL EnableDelayedExpansionfor /f "tokens=*" %%a in ('type WWN.txt') do ( Set WWN=%%a Echo WWN is !WWN! for /f "tokens=1-2 delims=:" %%i in ('type DirPort.txt') do ( Set Dir=%%i Set Port=%%j Echo Dir is !Dir! Port is !Port! echo - symmask -sid -wwn %%a -dir %%i -p %%j -noprompt >>WWNDirport.txt ) Echo WWN Processed is !WWN! >>WWNDIRPORT.txt )Firstly thanks for the reply. I've tried using the exclamation marks too but that will just echo "Dir is !Dir! Port is !Port! "I'm not sure when to use exclamation marks and when to use percentage signs in general. any other ideas?Tony Link to comment Share on other sites More sharing options...
Yzöwl Posted December 13, 2010 Share Posted December 13, 2010 Try turning echoing off!Make this your first line and run the script again.@Echo offThen when you've finished kicking yourself at reading the wrong lines in the console output try changing the code slightly:@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "TOKENS=*" %%# IN (WWN.TXT) DO ( SET WWN=%%# ECHO=WWN IS !WWN! FOR /F "TOKENS=1-2DELIMS=:" %%* IN (DIRPORT.TXT) DO ( SET DIR=%%* SET PORT=%%+ ECHO=DIR IS !DIR! PORT IS !PORT! >>WWNDirport.txt ECHO=- symmask -sid -wwn %%# -dir %%* -p %%+ -noprompt ) >>WWNDirport.txt ECHO=WWN Processed IS !WWN! ) Link to comment Share on other sites More sharing options...
jaclaz Posted December 13, 2010 Share Posted December 13, 2010 @TonyCRead attentively THIS :http://www.robvanderwoude.com/variableexpansion.phpjaclaz Link to comment Share on other sites More sharing options...
TonyC Posted December 14, 2010 Author Share Posted December 14, 2010 Try turning echoing off!Make this your first line and run the script again.@Echo offThen when you've finished kicking yourself at reading the wrong lines in the console output try changing the code slightly:@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "TOKENS=*" %%# IN (WWN.TXT) DO ( SET WWN=%%# ECHO=WWN IS !WWN! FOR /F "TOKENS=1-2DELIMS=:" %%* IN (DIRPORT.TXT) DO ( SET DIR=%%* SET PORT=%%+ ECHO=DIR IS !DIR! PORT IS !PORT! >>WWNDirport.txt ECHO=- symmask -sid -wwn %%# -dir %%* -p %%+ -noprompt ) >>WWNDirport.txt ECHO=WWN Processed IS !WWN! )Yzöwl, thanks a million for your help. I actualy had echo off set originally but i wanted to see how the script was processing so i knocked it off. Forgot to reset it.Script working great. Link to comment Share on other sites More sharing options...
TonyC Posted December 14, 2010 Author Share Posted December 14, 2010 @TonyCRead attentively THIS :http://www.robvanderwoude.com/variableexpansion.phpjaclaz2. The variable whose expansion should be delayed should be surrounded by exclamation marks instead of percent signs. aha Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now