Page 1 of 1

Combining contents of variables

Posted: 24 Oct 2011 02:46
by Rileyh
Hi Dostips community,
In response to the post on "New Technic" about the way to read multiple lines in a text file (note- it didn't work on my machine; I will post my issue on another topic) I wanted to find out if I could make my batch file set each line of a text file as a variable and make another variable that combines the data in the rest of the variables.
Then it should echo that variable.

Help will be greatly appreciated,
Rileyh

Re: Combining contents of variables

Posted: 24 Oct 2011 03:23
by jeb
Hi Rileyh,

what do you tried and at which line in your code you got problems?

jeb

Re: Combining contents of variables

Posted: 24 Oct 2011 03:56
by Rileyh
Basically I am having trouble with all of it:

Code: Select all

< myfile.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
)
set line

I cannot get it to echo the %line1% or any of them for that matter.

Re: Combining contents of variables

Posted: 24 Oct 2011 05:11
by jeb
Hi,

I tested it with

Code: Select all

@echo off
( for /L %%n in (1 1 10) do echo This is line%%n ) > myfile.txt
< myfile.txt (
  set /p line1=
  set /p line2=
  set /p line3=
  set /p line4=
  set /p line5=
)
set line
echo %line1%,%line2%,%line3%


And get the expected results, I can't see any problems.

jeb

Re: Combining contents of variables

Posted: 24 Oct 2011 23:21
by Rileyh
Thanks jeb, it worked. You have to admit it is a cool technique, huh?

Re: Combining contents of variables

Posted: 25 Oct 2011 10:51
by Ed Dyreen
'
Yes it's cool, Jeb introduced it to us :)

respect.