Combine multiple lines from one text file into one line

batch-file, string, windows

Solution

@echo off
setlocal enableDelayedExpansion
set "var="
for /f "usebackq" %%A in ("test.txt") do set var=!var!%%A
echo !var!

Edit I assumed "END" does not physically exist in your file. If it does exist, then you can add the following line after the FOR statement to strip off the last 3 characters.

set "!var!=!var:~0,-3!"

Problem

So I have a file with multiple lines of letters and numbers as shown: ``` a 1 h 7 G k 3 l ``` END I need a type of code that combines them together and preferably outputs it into a variable as shown: ``` var=a1h7Gk2l ``` Any help would be appreciated.

Original source