batch file with 2 "For /F" loops

BlackieHamel

Board Regular
Joined
May 9, 2014
Messages
93
I have been using a program to make word puzzles, and it runs in a command window. I use a batch file to input sets of 3-letter combinations, using a FOR /F loop, like this:
Code:
FOR /F "tokens=1,2" %%A in (input1.txt) DO puzzlemaker bow %%A ase %%B

In this example, I have a file, input.txt, with many rows containing two trigrams. Here's the beginning 7 rows of input.txt

ABS ENT
ACR NOU
ACU AIN
AFT ATH
AIR ACK
AIR DER
AIR KET


The above code does a wonderful job of feeding these rows, one at a time, to puzzlemaker.exe. Here's what my dream enhancement would be. See the "bow" and "ase" in the code above. Suppose I have another file, input2.txt, in which

BOW ASE
is just the first line. If input1.txt has 15 lines and input2.txt has 10 lines, I would like a loop command that tries 15x10 = 150 possible sets of four arguments to follow puzzlemaker in the command.

Can this be done in batch file language?

Thanks.

Blackie
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I found my answer elsewhere, so I'll post it here in case anyone is interested. Here I'm replacing "puzzlemaker" with ECHO, since the puzzlemaker output is irrelevant.

Code:
FOR /F "tokens=1,2" %%A in (input1.txt) DO FOR /F "tokens=1,2" %%C in (input2.txt) DO echo %%A %%C %%B %%D

If INPUT1.TXT is
ABS ENT
ACR NOU
ACU AIN


and INPUT2.TXT is
DVE NCE
EEE VEZ
EER ICE


Then the above code will interlace the two files thus:

ABS DVE ENT NCE
ABS EEE ENT VEZ
ABS EER ENT ICE
ACR DVE NOU NCE
ACR EEE NOU VEZ
ACR EER NOU ICE
ACU DVE AIN NCE
ACU EEE AIN VEZ
ACU EER AIN ICE


The main thing I was missing was that second DO in the statement.

Blackie
 
  • Like
Reactions: yky
Upvote 0
Solution

Forum statistics

Threads
1,223,244
Messages
6,170,976
Members
452,372
Latest member
Natalie18

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top