For /F to process multiple lines

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AR Coding
Posts: 53
Joined: 02 May 2021 21:16

For /F to process multiple lines

#1 Post by AR Coding » 27 May 2021 08:52

Hi, im pretty new to batch , and im not sure if this topic was spoken about Already on this forum. Im not very good at searching. So hear is my question:

is it possible for, for /f to process a command that outputs more then one line?
Here is my example:
For /F "delims=:" %%G in ('systeminfo') do (
set "%%G=%%H"
rem HERE IS WHERE I GET STUCK
)

%%G is going to equal OS NAME and %%H is going to equal AR Coding.
I want for to process all the lines. I want to be able to set all the lines after that also as variables. Is that possible?

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: For /F to process multiple lines

#2 Post by npocmaka_ » 27 May 2021 14:18

you havent defined the tokens you want to get.

try with

Code: Select all

For /F "tokens=1* delims=:" %%G in (
  'systeminfo'
) do (
  set "%%G=%%H"
)

tokens option will assign the string before the first `:` to the %%G and everything else to the %%H

AR Coding
Posts: 53
Joined: 02 May 2021 21:16

Re: For /F to process multiple lines

#3 Post by AR Coding » 27 May 2021 16:46

Thank you so much for the fast reply! I didnt think it was necessary to specify which tokens i want.

Post Reply