Solved how to get output from two for loops?

October 24, 2016 at 06:59:52
Specs: Windows 64, Core i7 2GHz/16GB
Hi all,
I have the following input.txt file:

tr=min;JohnLoeffler
te=min;TimWalter
The aim of the batch file I want is to give me:

tr min;JohnLoeffler
te min;TimWalter
and the my batch file is:

setlocal EnableDelayedExpansion

for /f "tokens=1,2,3* delims=;" %%a in (E:\input.txt) do (
echo.%%a>current.tok
E:\ProtocoI\%%b

for /f " tokens=* delims= " %%a in (E:\input.txt) do (
call :sub1 %%a
)

GOTO :EOF
:sub1
echo %1 %2

echo.%1 %2; %%b;!RESULT!>>output.txt

)

GOTO :EOF
however the output I get is:
tr min; %b;
te min; %b;
note that I need that current.tok for using in further function I want to use and the second for loop is for dropping equal sign in te=min and tr=min. now I don't know how to work with these two for loops to have the correct mentioned output.
Can anyone help me?
Thanks in advace,
Elahe


See More: how to get output from two for loops?

Report •

#1
October 25, 2016 at 04:54:14
✔ Best Answer
for /f "tokens=1,* delims==" %%A in (input.txt) do (
	echo %%A %%B>>output.txt
        for /f "tokens=2* delims=;" %%C in ("%%B") do (
                echo %%C>current.tok
        )
)

No need to make it so complicated ;)
I am assuming you wanted the current.tok for later use, however if you only needed it to parse the string to remove the = sign, you can remove the for loop inside the first one.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •
Related Solutions


Ask Question