我使用awk将所有第7个字段用逗号分隔。
1,root,init,20,0.0,0.1,0:01.78
1008,root,migration/0,1,2.0,1.8,7:04.32
26542,peter.ca,top,20,1.9,0.1,5:42.78
18776,john.sel,awk,15,0.2,0.0,0:01.00
49841,murray.s,topsum,16,1.3,0.1,0:02.11
29806,peter.ca,bash,20,0.1,0.0,0:00.03
9845,murray.s,awk,18,0.5,0.2,0:14.01
6549,peter.ca,topsum,16,1.4,0.2,0:04.81
18746,john.sel,bash,20,0.1,0.0,0:00.50
24987,john.bel,who,20,3.0,1.1,0:00.01
5,root,watchdog/0,1,0.0,0.0,0:00.00
29874,murray.s,timeon,20,0.1,0.2,0:02.15
cat data.top | grep root | awk 'BEGIN { FS = "," } ; { print $7 }'
输出:
0:01.78
7:04.32
0:00.00
我正在尝试将这些添加在一起(我也假设总数将少于24小时,因此这不是问题。)
提前致谢。
答案 0 :(得分:3)
$ awk -F, '/root/{split($7, t, ":"); sum+=60*t[1]+t[2]}; END{print sum}' input.txt
426.1
$ date -ud @426.1 +%T.%N | sed 's/0*$//'
00:07:06.1