1.11M Members

How to concatenate lines in batch

 
0
 

I have an batch script that needs to concatenate several hundred of lines (72 chars) in one long line for base64 to decode. He used line reading because of the windows XP line limit (8191 chars per line).

The script currently has 2 issues at result:

It exports with 2xquote character between my 72 char lines (like so: "addf4534@$") and base64 doesn't like that
It creates several 2-3 lines extra. The last line being the correct one.

Here is the script (install.zip its what is going to be encoded for later decoding):

@echo off
CALL D:\utilities\base64.exe -e install.zip install.txt
set "string="
::call :concat with %%a between double quotes because the two equal characters at the end of the string won't be removed
set lines=0
for /f "tokens=1 delims=¶" %%a in (install.txt) do call :concat "%%a"
::now remove all double quotes from the string (safe because base64 doesn'd use double quotes in encoding)
set string=%string:"=%

echo %string%>>install_no_returns.txt
goto :eof
:concat
set /A lines+=1
echo %lines%
set "string=%string%%1"
pause
if %lines%==50 (
    set lines=0
    echo %string%
    set string=%string:"=%
    echo %string%>>install_no_returns.txt
    pause
    set "string="
)
goto :eof

Can you help me with fixing it? Thanks

You
Post:
Start New Discussion
View similar articles that have also been tagged: