0
我有一個名爲kmeans_fastflow.log日誌文件看起來像這樣:awk來重新安排在執行數據日誌行
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 8.001152
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.981428
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.986656
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.979782
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.980070
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.987722
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.980716
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.980209
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.982284
data_set: data_set_1.txt number_of_threads: 1 execution_time_in_seconds: 7.979446
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.003821
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.003638
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.003149
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.005415
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.003460
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.002836
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.005717
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.006178
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.004005
data_set: data_set_1.txt number_of_threads: 2 execution_time_in_seconds: 4.004230
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.673844
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.673601
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.675926
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.674989
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.673274
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.677280
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.676808
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.673376
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.672576
data_set: data_set_1.txt number_of_threads: 3 execution_time_in_seconds: 2.673550
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.008327
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.007571
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.007797
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.007576
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.010466
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.008056
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.007402
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.006869
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.006896
data_set: data_set_1.txt number_of_threads: 4 execution_time_in_seconds: 2.007455
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608951
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.609970
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608875
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608379
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608383
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608388
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.607613
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.608727
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.609643
data_set: data_set_1.txt number_of_threads: 5 execution_time_in_seconds: 1.610055
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.343102
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.342790
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.347415
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.342613
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.343710
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.343529
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.345136
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.343854
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.342421
data_set: data_set_1.txt number_of_threads: 6 execution_time_in_seconds: 1.343624
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.153126
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.153022
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.152828
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.154386
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.152602
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.152872
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.153024
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.154684
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.153598
data_set: data_set_1.txt number_of_threads: 7 execution_time_in_seconds: 1.153146
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.011499
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.012181
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.011727
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.012070
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.011569
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.009917
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.011749
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.010674
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.010277
data_set: data_set_1.txt number_of_threads: 8 execution_time_in_seconds: 1.010382
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899709
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.900500
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.900231
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899769
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899652
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.900219
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.900431
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899219
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899579
data_set: data_set_1.txt number_of_threads: 9 execution_time_in_seconds: 0.899830
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.811642
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.811074
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.812207
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.810524
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.812218
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.811673
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.810863
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.812428
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.811251
data_set: data_set_1.txt number_of_threads: 10 execution_time_in_seconds: 0.810584
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.738681
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739885
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.740058
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739330
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739168
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739263
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739292
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.738528
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739389
data_set: data_set_1.txt number_of_threads: 11 execution_time_in_seconds: 0.739759
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.679359
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.678121
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.680982
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.682098
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.679681
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.678525
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.679727
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.679983
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.678458
data_set: data_set_1.txt number_of_threads: 12 execution_time_in_seconds: 0.678074
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.425779
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.417835
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.426430
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.500974
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.447586
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.411380
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.453845
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.480448
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.442289
data_set: data_set_2.txt number_of_threads: 1 execution_time_in_seconds: 56.394068
.
.
.
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.772698
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.761998
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.743285
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.746927
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.746411
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.758229
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.772117
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.767569
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.759577
data_set: data_set_2.txt number_of_threads: 12 execution_time_in_seconds: 4.753897
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.251694
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.348788
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.281708
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.278013
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.299754
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.443212
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.300965
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.374555
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.307755
data_set: data_set_3.txt number_of_threads: 1 execution_time_in_seconds: 89.342808
.
.
.
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.533035
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.556848
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.558419
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.557569
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.533890
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.565937
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.579489
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.546736
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.539902
data_set: data_set_3.txt number_of_threads: 12 execution_time_in_seconds: 7.552226
正如我們所看到的,number_of_threads從1到12,有變化每個執行10次,這些數據按數據集排序,可以是data_set_1,data_set_2和data_set_3。期望的輸出是按線程數排序的執行時間,而不是數據集。這樣的輸出中能夠獲得執行這個單awk腳本:
awk ' {if ($4 == "1") {print $3, $4, $6;}} ' kmeans_fastflow.log > t.dat
awk ' {if ($4 == "2") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "3") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "4") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "5") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "6") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "7") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "8") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "9") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "10") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "11") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
awk ' {if ($4 == "12") {print $3, $4, $6;}} ' kmeans_fastflow.log >> t.dat
這給所需的輸出:
number_of_threads: 1 8.001152
number_of_threads: 1 7.981428
number_of_threads: 1 7.986656
number_of_threads: 1 7.979782
number_of_threads: 1 7.980070
number_of_threads: 1 7.987722
number_of_threads: 1 7.980716
number_of_threads: 1 7.980209
number_of_threads: 1 7.982284
number_of_threads: 1 7.979446
number_of_threads: 1 56.425779
number_of_threads: 1 56.417835
number_of_threads: 1 56.426430
number_of_threads: 1 56.500974
number_of_threads: 1 56.447586
number_of_threads: 1 56.411380
number_of_threads: 1 56.453845
number_of_threads: 1 56.480448
number_of_threads: 1 56.442289
number_of_threads: 1 56.394068
number_of_threads: 1 89.251694
number_of_threads: 1 89.348788
number_of_threads: 1 89.281708
number_of_threads: 1 89.278013
number_of_threads: 1 89.299754
number_of_threads: 1 89.443212
number_of_threads: 1 89.300965
number_of_threads: 1 89.374555
number_of_threads: 1 89.307755
number_of_threads: 1 89.342808
number_of_threads: 2 4.003821
number_of_threads: 2 4.003638
number_of_threads: 2 4.003149
number_of_threads: 2 4.005415
number_of_threads: 2 4.003460
number_of_threads: 2 4.002836
number_of_threads: 2 4.005717
number_of_threads: 2 4.006178
number_of_threads: 2 4.004005
number_of_threads: 2 4.004230
number_of_threads: 2 28.258078
number_of_threads: 2 28.249284
number_of_threads: 2 28.264375
number_of_threads: 2 28.273207
number_of_threads: 2 28.228176
number_of_threads: 2 28.268416
number_of_threads: 2 28.240788
number_of_threads: 2 28.256000
number_of_threads: 2 28.262026
number_of_threads: 2 28.239830
number_of_threads: 2 44.681847
number_of_threads: 2 44.709311
number_of_threads: 2 44.668623
number_of_threads: 2 44.659865
number_of_threads: 2 44.699392
number_of_threads: 2 44.686959
number_of_threads: 2 44.671320
number_of_threads: 2 44.708551
number_of_threads: 2 44.731599
number_of_threads: 2 44.694352
.
.
.
number_of_threads: 12 0.679359
number_of_threads: 12 0.678121
number_of_threads: 12 0.680982
number_of_threads: 12 0.682098
number_of_threads: 12 0.679681
number_of_threads: 12 0.678525
number_of_threads: 12 0.679727
number_of_threads: 12 0.679983
number_of_threads: 12 0.678458
number_of_threads: 12 0.678074
number_of_threads: 12 4.772698
number_of_threads: 12 4.761998
number_of_threads: 12 4.743285
number_of_threads: 12 4.746927
number_of_threads: 12 4.746411
number_of_threads: 12 4.758229
number_of_threads: 12 4.772117
number_of_threads: 12 4.767569
number_of_threads: 12 4.759577
number_of_threads: 12 4.753897
number_of_threads: 12 7.533035
number_of_threads: 12 7.556848
number_of_threads: 12 7.558419
number_of_threads: 12 7.557569
number_of_threads: 12 7.533890
number_of_threads: 12 7.565937
number_of_threads: 12 7.579489
number_of_threads: 12 7.546736
number_of_threads: 12 7.539902
number_of_threads: 12 7.552226
如何使自動化此腳本,以便它給出了這樣的期望輸出t.dat? (請注意,如果在第一次寫入(>)後可以將結果附加到同一文件(使用>>),那將會更好)。
這是一個聰明的做法! – Lucas