Combining contents of variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Combining contents of variables

#1 Post by Rileyh » 24 Oct 2011 02:46

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

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Combining contents of variables

#2 Post by jeb » 24 Oct 2011 03:23

Hi Rileyh,

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

jeb

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: Combining contents of variables

#3 Post by Rileyh » 24 Oct 2011 03:56

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.

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Combining contents of variables

#4 Post by jeb » 24 Oct 2011 05:11

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

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: Combining contents of variables

#5 Post by Rileyh » 24 Oct 2011 23:21

Thanks jeb, it worked. You have to admit it is a cool technique, huh?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Combining contents of variables

#6 Post by Ed Dyreen » 25 Oct 2011 10:51

'
Yes it's cool, Jeb introduced it to us :)

respect.

Post Reply