Pulling information from a text file using for /f

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Pulling information from a text file using for /f

#1 Post by MKANET » 06 Apr 2012 20:03

I need to ultimately end up with two variables in each for /f loop
s%% (first token in each line)
t%% (everything after the first delimiter)


----------- text.txt --------------
S8F1TR4 Westwood CA 8F1
S86cTR4 Crenshaw 026
S8BDTR4 Inglewood CA 971
S8AFTR4 Tri Counties ADO CA H89
S8CATR4 Thousand Oaks CA A09
S887TR4 Boyle Heights CA 904
S86ETR4 Compton 434
-----------------------------------


so, for example:
s%%=S8F1TR4 , t%%=Westwood CA 8F1
s%%=S86cTR4 , t%%=Crenshaw 026

What's the simplest way have t%% = everything after the first space delimiter? Thanks in advance!

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Pulling information from a text file using for /f

#2 Post by dbenham » 06 Apr 2012 20:17

Code: Select all

for /f "tokens=1*" %%s in (test.txt) do (
  echo s=%%s
  echo t=%%t
)

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Pulling information from a text file using for /f

#3 Post by MKANET » 06 Apr 2012 21:11

thanks, I just have one more hurdle to go..

%%t has spaces in it. So when I try to pass %%t to an external batch files; such as....

call "external.cmd" %%s %%t

---------external.cmd----------
set server=%1
set location=%2

echo %location%
-------------------------------------

.... %location% doesn't get the entire string (originally from %%t). If I put double-quotes around %%t, I get the entire string; but, unfortunately, the double-quotes show too.

How can I get the entire string without the double-quotes showing? Thanks so much!

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

Re: Pulling information from a text file using for /f

#4 Post by Ed Dyreen » 06 Apr 2012 21:39

Code: Select all

set "server=%~1"
set "location=%~2"

for /? |more

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Pulling information from a text file using for /f

#5 Post by foxidrive » 06 Apr 2012 22:00

MKANET wrote:thanks, I just have one more hurdle to go..

%%t has spaces in it. So when I try to pass %%t to an external batch files; such as....

call "external.cmd" %%s %%t

How can I get the entire string without the double-quotes showing? Thanks so much!


double quote the variables and use what Ed has provided.

call "external.cmd" "%%s" "%%t"

MKANET
Posts: 160
Joined: 31 Mar 2012 21:31

Re: Pulling information from a text file using for /f

#6 Post by MKANET » 06 Apr 2012 22:04

Thanks. It works great. I really appreciate the help.

Post Reply