Hello everybody,

I have the following records in a file.

15:00:00.870;334
15:00:00.872;1314
15:00:00.889;334
15:00:00.890;334
15:00:00.891;334
15:00:00.892;334
15:00:00.909;212
15:00:00.910;334
15:00:00.929;334
15:00:00.948;334
15:00:00.950;334
15:00:00.969;334
15:00:00.970;334
15:00:00.990;334
15:00:01.010;295
15:00:01.011;334
15:00:01.012;334
15:00:01.029;334
15:00:01.030;334
15:00:01.048;334
15:00:01.049;334
15:00:01.051;1314

I want to count second column occurrence per second, so I would be able to get something like the below:

1314 occurred at 15:00:01 1 time
334 occurred at 15:00:01 6 time
295 occurred at 15:00:01 1 time
334 occurred at 15:00:00 12 time
212 occurred at 15:00:00 1 time
1314 occurred at 15:00:00 1 time

Would someone help me with this please, thanks in advance.

My advice is to expand the possible solutions to python or another scripting language. Just bash? Too much of a straight jacket approach.

Perhaps unreadable, but quick/easy/works -- you just have to master Perl5

perl -ne '$R{$1,$2}++ if m/^(\d+:\d+:\d+)[.]\d+;(\d+)$/; END{ for $tv (keys %R) { ($t,$v)=split($;,$tv); printf "%s occured at %s %d times\n",$v,$t,$R{$tv};}}' FILENAME

commented: "Now they have two problems." +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.