How to use "find" results as variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

How to use "find" results as variables

#1 Post by Rileyh » 07 Oct 2011 01:57

Hi,
I want to use the "find" command to look for text, and then set that result as a variable.
Can you do that?
If you can, then can you show me how to do so?
Any help would be appreciated.

Regards,
Rileyh

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to use "find" results as variables

#2 Post by aGerman » 07 Oct 2011 15:24

You have to use a FOR /F loop. But it's not enough information to give you detailed help.

Code: Select all

for /f "delims=" %%i in ('find "string" "file.txt"') do set "var=%%i"


Regards
aGerman

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: How to use "find" results as variables

#3 Post by Rileyh » 08 Oct 2011 00:48

aGerman,
What I want to do is look for text, and if the text that is found AND it matches another piece of text, do a command.
And could you provide an example and explanation of what a "for /f" loop is?

Any help would be appreciated,
Rileyh

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to use "find" results as variables

#4 Post by aGerman » 08 Oct 2011 08:48

No idea what exactly you are looking for, but you should have a look at the help of find (find /?) and findstr (findstr /?).

Type for /? in the command window and hit Enter to get more info or have a look at the Command Index.

Regards
aGerman

Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Re: How to use "find" results as variables

#5 Post by Rileyh » 08 Oct 2011 21:01

aGerman,
Thank you for the advice.
I tried "for /?" in cmd but it is far to complex text for me to understand.
Also, the examples provided relating to text search and looking for strings is very little and with no explanation.
Could you provide me with an explanation of for /f "tokens" and "delims=" please? (I can't get my head around it!!!)

Thank you for your time and effort,
Rileyh

Post Reply