使用sed或grep提取

cur*_*der 5 regex linux awk grep sed

我是grep和sed命令的新手.如何在bash脚本中使用grep或sed +50.0提取Core 0: +50.0°C (high = +80.0°C, crit = +90.0°C)

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)
Run Code Online (Sandbox Code Playgroud)

Bash脚本:

#!/bin/bash

temp=`sed -n '/^Core 0:      $/,/^(high/p' ~/Desktop/sensors.txt`

echo $temp
Run Code Online (Sandbox Code Playgroud)

anu*_*ava 2

使用grep -oP(PCRE 正则表达式):

grep -oP 'Core 0: +\K[+-]\d+\.\d+' ~/Desktop/sensors.txt
+50.0
Run Code Online (Sandbox Code Playgroud)