連想配列を使っていますので、順番通りに駅名が出ませんけど、もう少し頑張ればできるでしょう。
3桁区切りも同様。
bash
1#!/usr/bin/awk -f
2{
3 station = $1;
4
5 passengers = $2;
6 gsub(/,/, "", passengers);
7
8 passengersAtStation[station] += passengers;
9}
10
11END {
12 for (station in passengersAtStation) {
13 printf("%s\t%d\n", station, passengersAtStation[station]);
14 }
15}
解決済になっていますけど、駅名を出現順に、乗降客数を3桁区切りで表示するバージョンを示しておきます。
bash
1#!/usr/bin/awk -f
2function putCommaAtEvery3Digits(input, output) {
3 for (output = ""; input >= 1000; input = int(input / 1000)) {
4 output = sprintf(",%03d", input % 1000) output;
5 }
6 output = input output;
7
8 return output;
9}
10
11
12function registerStation(station, stationIndex) {
13 for (stationIndex = 0; stationIndex < stationCount; stationIndex++) {
14 if (stationList[stationIndex] == station) {
15 return stationIndex;
16 }
17 }
18
19 stationList[stationCount++] = station;
20 return stationCount;
21}
22
23
24{
25 station = $1;
26 registerStation(station);
27
28 passengers = $2;
29 gsub(/,/, "", passengers);
30
31 passengersAtStation[station] += passengers;
32}
33
34
35END {
36 for (stationIndex = 0; stationIndex < stationCount; stationIndex++) {
37 station = stationList[stationIndex];
38 printf("%s\t%s\n", station, putCommaAtEvery3Digits(passengersAtStation[station]));
39 }
40}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/29 05:30
2017/04/29 05:46
2017/04/29 06:07
2017/04/29 11:51
2017/04/29 14:20