我对grep和sed命令相当新.如何使用grep或sed在bash脚本中从Core 0:50.0°C(高= 80.0°C,暴击= 90.0°C)中提取50.0?
acpitz-virtual-0 Adapter: Virtual device temp1: +50.0°C (crit = +89.0°C) temp2: +50.0°C (crit = +89.0°C) coretemp-isa-0000 Adapter: ISA adapter Core 0: +50.0°C (high = +80.0°C,crit = +90.0°C) Core 2: +47.0°C (high = +80.0°C,crit = +90.0°C)
Bash脚本:
#!/bin/bash temp=`sed -n '/^Core 0: $/,/^(high/p' ~/Desktop/sensors.txt` echo $temp
解决方法
使用grep -oP(PCRE正则表达式):
grep -oP 'Core 0: +\K[+-]\d+\.\d+' ~/Desktop/sensors.txt +50.0