B Todd Poole
B Todd Poole

Reputation: 49

Batch script not setting variable

I have (2) text files that a batch script will open, read line 2 and set a variable to the value of line 2. The text files only contain 3 lines, the first file is numbers, the second is letters. I am using the following to open, read and set:

for /f "token=1*delim=:" %%G in ('findstr /n "^" chnid.txt') do if %%G equ 2 set xcid=%%H
for /f "token=1*delim=:" %%L in ('findstr /n "^" cfile.txt') do if %%L equ 2 set xcfile=%%J

When executed it works great on setting xcid for the number but it never sets xcfile for the letters. During execution, I can see that it steps thru each line of the text file with the if statement and it shows the value of each line but it never sets the variable.

The chnid file has 3 lines with a group of numbers one each line:

48051
12547
89745

The cfile file has 3 lines with a group of letters on each line:

"abcdef"
"ghijkl"
"mnopqr"

Can anybody suggest whey it won't set the xcfile variable = %%J?

Thanks for any help

Upvotes: 2

Views: 168

Answers (2)

Magoo
Magoo

Reputation: 79982

2 basic reasons.

First, "2" is not contained in the file you are targeting.

Second, In normal alphabets, L is followed by M, not J. That may of course not be politically correct, as it probably offends dyslexics, so I may be out-of-date, but I reckon it's very likely to be a cause of your problem.

Upvotes: 0

foxidrive
foxidrive

Reputation: 41224

i think this is what you want

 set xcfile=%%M

Upvotes: 2

Related Questions