I have a txt file with input as -
First Line data here ...
Second, line data ; here
Third. line data here ..,
I have the following bat script code to read the txt file line by line and have value in tmp variable should ideally look like -
{ "s1":"First Line data here ...","s2":"Second, line data ; here","s3":"Third. line data here ..,"}
bat script code that is not giving me the expected output looks like -
@echo off
set /a count=1
set tmp=
SETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ data.txt"`) do (
set "var=%%a"
SETLOCAL EnableDelayedExpansion
set "var=!var:*:=!"
echo(!var!
call :processline !var!
ENDLOCAL
)
pause
goto :END
:processline
set txt="%*"
set inp="s%count%"
IF "!tmp!" EQU "" (
echo if called
set tmp=%inp%:%txt%
) ELSE (
echo else called
set tmp=%tmp%,%inp%:%txt%
)
set /a count+=1
exit /b 0
:END
echo end called
echo -------
echo %tmp%}
pause
through some debugging i noticed that line "set tmp=%inp%:%txt%" is actually not getting set in global scope and always remaining empty, how can I modify this code to achieve the desired json looking output in tmp ?