UPDATE: Well, initially I posted a solution to a more complex problem to get a complete separation of any line with any separator (just changing the separators). I read more decisions than the OP wanted, sorry. I think this time I obey the original requirements:
@echo off IF [%1] EQU [] echo get n ["user_string"] & goto :eof set token=%1 set /a "token+=1" set string= IF [%2] NEQ [] set string=%2 IF [%2] EQU [] set string="AAA BBB CCC DDD EEE FFF" FOR /F "tokens=%TOKEN%" %%G IN (%string%) DO echo %%~G
Another version with a better user interface:
@echo off IF [%1] EQU [] echo USAGE: get ["user_string"] n & goto :eof IF [%2] NEQ [] set string=%1 & set token=%2 & goto update_token set string="AAA BBB CCC DDD EEE FFF" set token=%1 :update_token set /a "token+=1" FOR /F "tokens=%TOKEN%" %%G IN (%string%) DO echo %%~G
Output Examples:
E:\utils\bat>get USAGE: get ["user_string"] n E:\utils\bat>get 5 FFF E:\utils\bat>get 6 E:\utils\bat>get "Hello World" 1 World
This is a batch file to separate path directories:
@echo off set string="%PATH%" :loop FOR /F "tokens=1* delims=;" %%G IN (%string%) DO ( for /f "tokens=*" %%g in ("%%G") do echo %%g set string="%%H" ) if %string% NEQ "" goto :loop
Second version:
@echo off set string="%PATH%" :loop FOR /F "tokens=1* delims=;" %%G IN (%string%) DO set line="%%G" & echo %line:"=% & set string="%%H" if %string% NEQ "" goto :loop
Third version:
@echo off set string="%PATH%" :loop FOR /F "tokens=1* delims=;" %%G IN (%string%) DO CALL :sub "%%G" "%%H" if %string% NEQ "" goto :loop goto :eof :sub set line=%1 echo %line:"=% set string=%2
carlos_lm Sep 18 '14 at 19:30 2014-09-18 19:30
source share