Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign command output to variable 1

Status
Not open for further replies.

PerditaX

Technical User
Oct 24, 2006
3
GB
Hi,

New to batch scripting & have not been able to find examples or info on the following...

want to assign the output of the 'find' command to a variable, in batch script.

eg: MyVariable = find /c "myString" c:/myfile.log

so, looking for the number of times myString appeard in myFile & assigning the output to a variable.

Win2000 help didn't have any info, and an internet search was fruitless... so still don't know how to make this 'work'.

Any pointers would be appreciated,

Thanks.
P.
 
Try parsing the output. In a command prompt your command would return something like:
-------- MYFILE.LOG: 1
This line:
Code:
for /f "Tokens=3 delims= " %%i in ('find /c "myString" c:\myfile.log') do set MyVariable=%%i
says "Parse the output of the Find command. Use a space to delimit the tokens (separate words). Give me token number 3 in %%i, then set MyVariable to %%i"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top