Board logo

标题: [文本处理] 求助批处理提取字段输出的变量去掉% [打印本页]

作者: smtcao008    时间: 2023-10-28 14:33     标题: 求助批处理提取字段输出的变量去掉%

如下是TXT 内容
Description,Value
Battery Name,02DL008
Manufacture Name,SMP
Serial Number, 2669
Manufacture Date,
Power State,"Charging, AC Power"
Current Capacity (in %),67.6%
Current Capacity Value,"29,920 mWh"
Full Charged Capacity,"44,260 mWh"
Designed Capacity,"50,450 mWh"
Battery Health,87.7%
Voltage,"12,868 millivolts "
Charge/Discharge Rate ,"32,852 milliwatts "
Chemistry ,LiP
Low Battery Capacity (1),200 mWh
Low Battery Capacity (2),"2,213 mWh"
Critical Bias,
Number of charge/discharge cycles,184
Battery Temperature,
Remaining battery time for the current activity (Estimated),
Full battery time for the current activity (Estimated),
Remaining time for charging the battery (Estimated),
Total  time for charging the battery (Estimated),

提取11行Battery Health,87.7%中的87.7%但是不要%做输出变量,上个帖子有前辈代码教了 提取指定行数和指定字节
for /f "tokens=2 delims=," %%i in ('type scomma.txt^|find "Battery Health"') do set H=%%i  输出结果是H变量为87.7%   我怎么让它没%好,纯输出数字呢?因为我发现百分比不能再批处理中对比大小,
if %H% GTR 95% goto PASS 不能这么用。。。。。  去掉%后这样 if %H% GTR 95 goto PASS  可以正常比对了,请教下
作者: terse    时间: 2023-10-28 14:49

都可以一试
  1. @echo off
  2. for /f "tokens=2 delims=,%%" %%i in ('findstr /ibc:"Battery Health" scomma.txt') do set h=%%i
  3. echo %h%
  4. pause
复制代码
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "tokens=2 delims=," %%i in ('findstr /ibc:"Battery Health" scomma.txt') do set h=%%i
  3. echo !h:%%=!
  4. pause
复制代码

作者: smtcao008    时间: 2023-10-28 14:53

回复 2# terse
啊!~是我钻牛角尖了,delims 可以断%号啊。。。。感谢感谢!我还以为%号很特殊 不能这么做。。。。。。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2