Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine multiple lines from one text file into one line

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.

like image 879
Bynari Avatar asked Nov 30 '25 22:11

Bynari


1 Answers

@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!"
like image 64
dbenham Avatar answered Dec 03 '25 19:12

dbenham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!