我想提取smartctl -a查询的原始值。 不幸的是,我无法创建findstr命令,因此命中只是在行的开头。
以下是smartctl的示例输出:
C:\>c:\Programme\smartmontools\bin\smartctl.exe -A /dev/hdb
smartctl 6.5 2016-05-07 r4318 [x86_64-w64-mingw32-win8.1] (sf-6.5-1)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 080 063 044 Pre-fail Always - 111886652
3 Spin_Up_Time 0x0003 097 097 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 40
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 078 060 030 Pre-fail Always - 67217403
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 1541
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 13
184 End-to-End_Error 0x0032 100 100 099 Old_age Always - 0
187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0
188 Command_Timeout 0x0032 100 099 000 Old_age Always - 4295032833
189 High_Fly_Writes 0x003a 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0022 066 062 045 Old_age Always - 34 (Min/Max 28/38)
191 G-Sense_Error_Rate 0x0032 100 100 000 Old_age Always - 0
192 Power-Off_Retract_Count 0x0032 100 100 000 Old_age Always - 8
193 Load_Cycle_Count 0x0032 100 100 000 Old_age Always - 98
194 Temperature_Celsius 0x0022 034 040 000 Old_age Always - 34 (0 11 0 0 0)
195 Hardware_ECC_Recovered 0x001a 051 003 000 Old_age Always - 111886652
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
以下代码工作正常,但我想搜索ID#列而不是Attribute_Name:
C:\>for /F "tokens=10" %a in ('c:\Programme\smartmontools\bin\smartctl.exe -a /dev/hdb ^| findstr "Seek_Error_Rate" ') do @echo %a
67221721
感谢您的贡献!
请原谅我的英语不好!
答案 0 :(得分:0)
这个怎么样:
findstr /R /B /C:"[ 0-9][ 0-9][0-9] "
这也可以匹配以数字开头的行,后跟一个空格,然后是另一个数字,但我认为无论如何都不会发生。如果有,请使用:
findstr /R /B /C:" [ 0-9][0-9] " /C:"[0-9][0-9][0-9] "
(您可以使用/C
指定多个搜索字符串,这些字符串是ORed。)