Page 1 of 1

Echo results of FOR /F loop on one line

Posted: 08 Dec 2011 12:27
by alleypuppy
Hello,

I have a text file that is appended to by a batch file. I want to echo the data of the file on one line using a FOR /F loop and set the result equal to a variable. I'm guessing this is possible, but I don't know how to do it. For example, here is my text file:

Code: Select all

0
1
2
3

I want the result to look like this:

Code: Select all

0123
Keep in mind that this file is constantly being added to.

Thanks for any help!

Re: Echo results of FOR /F loop on one line

Posted: 08 Dec 2011 12:53
by !k

Code: Select all

setlocal enabledelayedexpansion
set "$="
for /f "usebackq delims=" %%a in ("text.txt") do set "$=!$!%%a"
echo:!$!

:?:

Re: Echo results of FOR /F loop on one line

Posted: 08 Dec 2011 14:57
by alleypuppy
!k wrote:

Code: Select all

setlocal enabledelayedexpansion
set "$="
for /f "usebackq delims=" %%a in ("text.txt") do set "$=!$!%%a"
echo:!$!

:?:

Works perfectly, thanks!