興味があったのでPythonで書いてダミーのログを読ませてみましたが、これログがID別に時間通りに並んでいないとシェルスクリプトではつらいのでは。
Python
1import pandas as pd
2
3pd.set_option('display.unicode.east_asian_width', True)
4
5df = pd.read_csv("log.txt", dtype={'日付': 'object', 'ID': 'object', '時間': 'object'})
6# print(df)
7
8df2 = df.pivot_table(index=["日付", "ID", "コード"], columns="時間",
9 values="件数", aggfunc=sum)
10df2.columns.name = None
11df2 = df2.reset_index()
12# print(df2)
13
14df2.to_csv("converted_log", index=None)
result
1日付,ID,コード,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23
220210101,1000,aaaa,2,6,5,5,6,7,8,9,10,11,12,12,11,10,9,8,7,6,5,4,3,2,5
320210101,1001,bbbb,1,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4
log.txt
1日付,ID,コード,時間,件数
220210101,1000,aaaa,01,2
320210101,1000,aaaa,02,6
420210101,1000,aaaa,03,5
520210101,1000,aaaa,04,5
620210101,1000,aaaa,05,6
720210101,1000,aaaa,06,7
820210101,1000,aaaa,07,8
920210101,1000,aaaa,08,9
1020210101,1000,aaaa,09,10
1120210101,1000,aaaa,10,11
1220210101,1000,aaaa,11,12
1320210101,1000,aaaa,12,12
1420210101,1000,aaaa,13,11
1520210101,1000,aaaa,14,10
1620210101,1000,aaaa,15,9
1720210101,1000,aaaa,16,8
1820210101,1000,aaaa,17,7
1920210101,1000,aaaa,18,6
2020210101,1000,aaaa,19,5
2120210101,1000,aaaa,20,4
2220210101,1000,aaaa,21,3
2320210101,1000,aaaa,22,2
2420210101,1000,aaaa,23,5
2520210101,1001,bbbb,01,1
2620210101,1001,bbbb,02,2
2720210101,1001,bbbb,03,3
2820210101,1001,bbbb,04,3
2920210101,1001,bbbb,05,3
3020210101,1001,bbbb,06,3
3120210101,1001,bbbb,07,3
3220210101,1001,bbbb,08,3
3320210101,1001,bbbb,09,3
3420210101,1001,bbbb,10,3
3520210101,1001,bbbb,11,3
3620210101,1001,bbbb,12,3
3720210101,1001,bbbb,13,3
3820210101,1001,bbbb,14,3
3920210101,1001,bbbb,15,3
4020210101,1001,bbbb,16,3
4120210101,1001,bbbb,17,3
4220210101,1001,bbbb,18,3
4320210101,1001,bbbb,19,3
4420210101,1001,bbbb,20,3
4520210101,1001,bbbb,21,3
4620210101,1001,bbbb,22,3
4720210101,1001,bbbb,23,4