Echo results of FOR /F loop on one line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

Echo results of FOR /F loop on one line

#1 Post by alleypuppy » 08 Dec 2011 12:27

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!

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

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

#2 Post by !k » 08 Dec 2011 12:53

Code: Select all

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

:?:

alleypuppy
Posts: 82
Joined: 24 Apr 2011 19:20

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

#3 Post by alleypuppy » 08 Dec 2011 14:57

!k wrote:

Code: Select all

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

:?:

Works perfectly, thanks!

Post Reply