Eka*_*Eka 0 command-line cut-command
我在我的系统中安装了tlp以防止笔记本电脑过热,我使用此代码来检索当前的 CPU 温度。
tlp-stat -t
Run Code Online (Sandbox Code Playgroud)
上面命令的输出是这样的:
--- TLP 0.7 --------------------------------------------
+++ Temperatures
CPU temp = 47 [°C]
Fan speed = (not available)
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何只检索该输出的整数部分(即 47)。我尝试使用 cut 命令,但无法找到最佳结果。
这是我使用的剪切命令
tlp-stat -t | cut -d= -f2
Run Code Online (Sandbox Code Playgroud)
输出是
--- TLP 0.7 --------------------------------------------
+++ Temperatures
49 [°C]
(not available)
Run Code Online (Sandbox Code Playgroud)
如何优化我的cut
命令以仅获取两位整数值?
使用 awk:
... | awk '/CPU temp/ {print $4}'
Run Code Online (Sandbox Code Playgroud)
使用 grep:
... | grep -oP '^CPU temp.*=.* \K[0-9]+'
Run Code Online (Sandbox Code Playgroud)
与 sed:
... | sed -nE 's/^CPU temp.*=.* ([0-9]+).*/\1/p'
Run Code Online (Sandbox Code Playgroud)