加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 – 使用sed或grep提取

发布时间:2020-12-14 06:01:07 所属栏目:百科 来源:网络整理
导读:我对grep和sed命令相当新.如何使用grep或sed在bash脚本中从Core 0:50.0°C(高= 80.0°C,暴击= 90.0°C)中提取50.0? acpitz-virtual-0Adapter: Virtual devicetemp1: +50.0°C (crit = +89.0°C)temp2: +50.0°C (crit = +89.0°C)coretemp-isa-0000Adapter
我对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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读