Assigning a value from a text file to a variable

2019-07-27 11:25发布

I have a text file with the following data:

JVM Heap Info: Sat Sep 14 03:40:30 MDT 2013

JVM Memory Information:

  maxMem:   4,263,706,624 (4,163,776k)

  totalMem: 4,263,706,624 (4,163,776k)

  freeMem:  3,169,325,008 (3,095,043k)

  usedMem:  1,094,381,616 (1,068,732k)

  availableProcessors:  64

From the text file, I need to get the used memory value (1,094,381,616) and store it in a variable so that I can use it for further processing. Can anyone please let me know how to accomplish this using batch commands?

1条回答
ら.Afraid
2楼-- · 2019-07-27 12:19

You can extract the value from the text file like this:

@echo off & setlocal

for /f "tokens=2" %%a in ('findstr usedMem "%~1"') do set "mem=%%~a"

echo %mem%

Call the script with the path to the file:

C:\>script.cmd "C:\path\to\data.txt"
1,094,381,616
查看更多
登录 后发表回答