【发布时间】:2013-09-09 16:01:03
【问题描述】:
我对 grep 和 sed 命令相当陌生。如何在 bash 脚本中使用 grep 或 sed 从 Core 0: +50.0°C (high = +80.0°C, crit = +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
【问题讨论】:
-
对于需要提取的内容是否有更具体的规则?是否总是紧跟在
Core 0:之后但在(之前? -
我只想提取 Core 0: 和 (.) 之间存在的任何内容。如果可能的话,消除 Core 0: 和 +50.0(动态)之间的额外空间