Is it possible to have for loop inside another for loop ?
I have two files, the first file contains
...
"bla","bli","blu",XX
"bla","bli","blu",YY
...
And the second one contains:
...
XX,some string
XX,some string
YY,diferent string
YY,diferent string
...
And what I want to do is write to one file lines like :
...
"bla","bli","blu",some string
"bla","bli","blu",diferent string
...
My best try isn't working
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
)
EDIT:
I have problem with SHIFT :/ commented in code below
@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