在平面文件我有以下的test.txt萃取柱和使用AWK
cat test.txt
2017-08-26 15:38:51.4,1.6814,DEV,TEST
2017-08-26 15:38:51.4,0.53080004,DEV,TEST
2017-08-26 15:38:51.4,1.7757,DEV,TEST
2017-08-26 15:38:51.4,0.5666,DEV,TEST
2017-08-26 15:38:55.324,0.465,DEV,TEST
2017-08-26 15:38:55.324,0.4734,DEV,TEST
2017-08-26 15:38:55.324,1.6006,DEV,TEST
2017-08-26 15:38:55.324,0.4886,DEV,TEST
2017-08-26 15:38:55.324,1.6165,DEV,TEST
2017-08-26 15:38:55.324,0.46879998,DEV,TEST
2017-08-26 15:38:55.324,1.5161,DEV,TEST
2017-08-26 15:38:55.324,3.1766,DEV,TEST
2017-08-26 15:38:55.324,1.5461,DEV,TEST
2017-08-26 15:38:55.324,1.5679,DEV,TEST
2017-08-26 15:38:55.324,1.5355,DEV,TEST
2017-08-26 15:38:55.324,0.49389997,DEV,TEST
2017-08-26 15:38:55.324,0.50909996,DEV,TEST
2017-08-26 15:38:55.325,1.7934,DEV,TEST
2017-08-26 15:38:55.325,3.005,DEV,TEST
2017-08-26 15:38:55.325,0.6599,DEV,TEST
2017-08-26 15:38:55.325,0.5711,DEV,TEST
2017-08-26 15:38:55.325,1.5683999,DEV,TEST
我需要以下輸出
2017-08-26 15:38:51 4.5528
15:38:55 23.0402
其中15時38分51秒聚集的值是時間戳以毫秒爲單位截斷並且4.5528是對應於15:38:51時間戳的所有值的總和
與15:38:55相同是截斷了毫秒的時間戳並且23.0402是所有值的總和correspo nding至15時38分55秒的時間戳
我想這awk命令
$
awk -F ".," '{a[$1] += $2} END{for (i in a) print i, a[i]}' test.txt
2017-08-26 15:38:51. 4.5528
2017-08-26 15:38:55.32 23.0402
,但並不如預期的輸出。
應該不是在第一列 第二列顯示一次約會應該有截去和時間戳下的所有相應值的和在第三列