Linux

如何在 Linux 中返回返回值的總和?

  • June 23, 2021

如何返回“更新時間(秒):”和“Gups:”的總和以找到每個的總值?

我很感激任何幫助!

程式碼:

root@:~/gups# mpirun --allow-run-as-root -np 2 gups_vanilla 20 1000 1024
Number of procs: 1
Vector size: 1048576
Max datums during comm: 0
Max datums after comm: 1024
Excess datums (frac): 0 (0)
Bad locality count: 0
Update time (secs):     0.003
Gups:  0.301295
Number of procs: 1
Vector size: 1048576
Max datums during comm: 0
Max datums after comm: 1024
Excess datums (frac): 0 (0)
Bad locality count: 0
Update time (secs):     0.004
Gups:  0.233969
root@:~/gups# mpirun --allow-run-as-root -np 2 gups_vanilla 20 1000 1024 | awk -F: '$1 == "Gups"{sum+=$2}END{print sum}'
0.429367

如果沒有您的輸出,我無法對此進行測試,但您應該可以使用 awk:

<command> | awk -F: '$1 == "Gups"{sum+=$2}END{print sum}' 

-F:告訴 awk:用作欄位分隔符,然後對於第一個欄位等於Gups第二個欄位的任何記錄將添加到sum變數中。awk 完成讀取所有記錄後,它將列印sum

引用自:https://unix.stackexchange.com/questions/655386