Page 1 of 1

Pulling information from a text file using for /f

Posted: 06 Apr 2012 20:03
by MKANET
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!

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

Posted: 06 Apr 2012 20:17
by dbenham

Code: Select all

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

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

Posted: 06 Apr 2012 21:11
by MKANET
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!

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

Posted: 06 Apr 2012 21:39
by Ed Dyreen

Code: Select all

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

for /? |more

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

Posted: 06 Apr 2012 22:00
by foxidrive
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"

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

Posted: 06 Apr 2012 22:04
by MKANET
Thanks. It works great. I really appreciate the help.