更新时间:2022-11-12 08:44:46
您已经将所需的温度存储在一个数组中,然后您可以用它们进行数学计算.
There you have desired temperatures stored in an array, you can then do the math with them.
arr=( $( IFS=$'\n' gawk 'BEGIN{ RS="\n\n"} { if($0 ~/amdgpu/) print $0 }' test.txt | gawk 'BEGIN{ FS="[+.]" } { if($1 ~/temp1:/) 打印 $2 }' ) )回声${arr[*]}"50 47 52 51 53
test.txt 包含您的示例输出.从传感器命令获取输入(未测试)
test.txt contains your sample output. Getting input from sensors command (not tested)
arr=( $(sensors | IFS=$'\n' gawk 'BEGIN{ RS="\n\n"} { if($0 ~/amdgpu/) print $0 }' | gawk 'BEGIN{ FS="[+.]" } { if($1 ~/temp1:/) 打印 $2 }' ) )回声${arr[*]}"50 47 52 51 53