从文本文件挑一条线,并将其设置为可变 [英] Pick a line from text file and set it as variable

查看:137
本文介绍了从文本文件挑一条线,并将其设置为可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的不知道如何使结果从下面的文本文件在我的批处理文件中的一个变量。

首先,我需要运行这个WMIC行。

  WMIC PAGEFILE得到AllocatedBaseSize /值>的test.txt

这test.txt的结果占地6行中,只有第三行有字符,这是一个我需要设置为我的变量。

test.txt的内容

  AllocatedBaseSize = 16328


解决方案

这将直接设置变量没有中间文件

  FOR / F令牌= *%%一中(
    WMIC PAGEFILE得到AllocatedBaseSize /值^ |寻找=
)在(%%一)不设置AllocatedBaseSize = %% B%% b执行回声%AllocatedBaseSize%

循环是消除额外的CR(0X0D)字符并从WMIC输出线的末端

I really have no idea how to make the result from the following text file in to a variable in my batch file.

First I need to run this WMIC line.

wmic PAGEFILE get AllocatedBaseSize /Value > test.txt

The result from test.txt occupies 6 lines, only the third line has the characters and this is the one I need to set as my variable.

Content of test.txt

AllocatedBaseSize=16328

解决方案

This will directly set the variable without an intermediate file

for /f "tokens=*" %%a in (
    'wmic PAGEFILE get AllocatedBaseSize /value^|find "="'
) do for %%b in (%%a) do set "AllocatedBaseSize=%%b"

echo %AllocatedBaseSize%

The double for loop is to eliminate an additional CR (0x0D) character and the end of the output lines from WMIC

这篇关于从文本文件挑一条线,并将其设置为可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆