Q:

Batch pull a variable from a random line in a text file, then another variable based on that number

I'm trying to make a batch file which selects a variable from one text file via choosing a random line, then sets the entire line as a variable. Then it sets a second variable using the same line number previously generated to select the first variable to set a second variable from a second text file. Example: If the batch file randomly selects the 4th line of test1.txt as a variable, it will then select the 4th line of test2.txt as the variable.
The variables from the two text files are related, and I can't think of a way to get a batch file to read one line of a text file and get two variables out of it. (Especially not when one will be a text string and the other will be a number.)
I found this code which can randomly pull a line from a text file then store it as a variable.
@echo off
setlocal EnableDelayedExpansion
set INPUT_FILE="test1.txt"

:: # Count the number of lines in the text file and generate a random number
for /f "usebackq" %%a in (`find /V /C "" ^< %INPUT_FILE%`) do set lines=%%a
set /a randnum=%RANDOM% * lines / 32768 + 1, skiplines=randnum-1

:: # Extract the line from the file
set skip=
if %skiplines% gtr 0 set skip=skip=%skiplines%
for /f "usebackq %skip% delims=" %%a in (%INPUT_FILE%) do set "randline=%%a" 
set line=!randline!

If this is run, it will return the entire string existing at the randomly chosen line from within test1.txt. But I can't for the life of me find a way to store the variable %skiplines%, and then use that to pull another variable from test2.txt.
I have tried several things. Most notably:
set /a "line = 0"
for /f "tokens=2 delims= " %%a in (test2.txt) do (
set /a "line = line + 1"
if !line!==%skiplines% set thing=%%a

When this is run, the batch file processing exits instantly, or if it gets to the output it will say Echo is off instead of the output that should come from test2.txt. I don't know what to do.

A:

To correct your example code, you'd need
for /f "usebackq %skip% delims=" %%a in (%INPUT_FILE%) do set "randline=%%a"&GOTO FOUNDLINE1
:FOUNDLINE1
set line=%randline%

Although why you'd want to set line when the dta you evidently want is in randline is a mystery to me. I'd use
for /f "usebackq %skip% delims=" %%a in (%INPUT_FILE%) do set "line=%%a"&GOTO FOUNDLINE1
:FOUNDLINE1

And to select the same line number from the second file, the code would be
for /f "usebackq %skip% delims=" %%a in (%INPUT_FILE2%) do set "line2=%%a"&GOTO FOUNDLINE2
:FOUNDLINE2

But since you've given no indication of the contents of the files or what you actully want given the file contents, anything more is speculation.
You haven't shown the closing parenthesis in the second codefrag. Batch will object and terminate if that is missing.

