循環內部是否可以有for循環?批處理 - 用於循環的內部循環
我有兩個文件,第一個文件包含
...
"bla","bli","blu",XX
"bla","bli","blu",YY
...
,第二個包含:
...
XX,some string
XX,some string
YY,diferent string
YY,diferent string
...
而我想做的事就是寫一個文件行,如:
...
"bla","bli","blu",some string
"bla","bli","blu",diferent string
...
我的最佳嘗試不起作用
for /f "tokens=1-10 delims=," %%1 in (semi-final.txt) do (
:: echo "bla","bli","blu"
echo %%1,%%2,%%3,%%4,%%5,%%6, | tr -d "\r\n" >> final.txt
:: set var=XX or set var=YY
set var=%%7
for /f "tokens=1,2 delims=," %%1 in (codes.txt) do (
:: Find XX in codes.txt for exchange
if /i "%%2"=="!var!" echo %%1, | tr -d "\r\n" >> final.txt
)
::Other echo after that XX , isn't important
echo %%7,%%8,%%9,%%10 >> final.txt
)
編輯:
我有問題,SHIFT:/註釋在下面的代碼
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=1-11 delims=, skip=1" %%1 in (semi-final.txt) do (
echo %%1,%%2,%%3,%%4,%%5,%%6, >> final.txt
set var=%%7
set b=!var:~2,2!
call :inner !b!
shift
shift
shift
:: Still %%6 is the same asi in first command
echo %%6,%%7,%%8,%%9 >> final.txt
)
goto :eof
:inner
for /f "tokens=1,2 delims=," %%X in (codes.txt) do (
IF /i "%%Y"=="!b!" (
echo '%%X', >> final.txt
goto :next
)
)
echo '', >> final.txt
:next
goto :eof
請你能告訴我,有沒有一種可能的方式「其他」的聲明? –
如果你的意思是「其他」加上「如果」,當然,但這是另一個問題。如果你的意思是「else」,如「如果我沒有找到我正在尋找的for'使用',那麼去這裏」,然後否,但是你可以在循環之後包含一些代碼,並在找到匹配時跳過它。 – Avish
好吧,我也有移位問題... echo %% 6(prints「bla」)................ shift shift shift ... ............... echo %% 6仍然打印「bla」 –