

We can set the entire line if we want to, using an asterisk (*).įOR /f "tokens=* delims= " %%a IN (MyFile.txt) DO ECHO %%a Using the same logic as before, we can use the first, third, and sixth token.įOR /f 'tokens=1, 3, 6 delims= " %%a IN (MyFile.txt) DO ECHO %%a %%b %%c Now, just because we’ve decided to become very aggressive, we’re going to attempt to get the words “Hello”, “How”, and “doing”. If I wanted to, I could set all the variables, then just echo %a %c %e, resulting in “How you today?” The batch file sets the first variable defined (%a) then will move on to the next one, in this case %b. Still using space as a delimiter, we can grab it with tokens 3-7.įOR /f 'tokens=3-7 delims= " %%a IN (MyFile.txt) DO ECHO %%a %%b %%c %%d %%e Now let’s say that we want the “How are you doing today?” portion.

How will we accomplish that? Using a space as a delimiter (separator) we can grab it with the second token.įOR /f "tokens=2 delims= " %%a IN (MyFile.txt) DO ECHO %%a Now, let’s pretend that we want is the word “World!”. It’s a little difficult to explain, so here’s an example. Tokens basically tell the batch file where to look to set the variable (%a). I am constantly hearing people asking “What do tokens and delims mean?”.

It might look something like this:įOR /f "tokens=* delims= " %%a IN (MyFile) DO ECHO %%a Quite often when writing a batch file, you will come across a FOR loop.
