将文本文件中的值分配给变量 [英] Assigning a value from a text file to a variable
本文介绍了将文本文件中的值分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含以下数据的文本文件:
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
从文本文件,我需要获得使用的内存值(1,094,381,616)并将其存储在一个变量中,以便我可以使用它进一步处理。任何人都可以让我知道如何使用批处理命令完成此操作。
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?
推荐答案
:
@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
这篇关于将文本文件中的值分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文