Sample Header Ad - 728x90

Uniq based on last field, keeping last line, and append number of duplicates

2 votes
2 answers
2788 views
I need some help to implement awk command in a bash script for implementing below logic. Tried sort/uniq combination, but no luck. I have a long list with time stamp and some number in front of it like below. [2020-09-15 09:03:21.835335] 1021 [2020-09-15 09:03:21.935335] 1021 [2020-09-15 09:03:22.835335] 1022 [2020-09-15 09:03:25.835335] 1022 [2020-09-15 09:04:21.835335] 1023 [2020-09-15 09:05:21.835335] 1023 [2020-09-15 09:04:22.835335] 1023 [2020-09-15 09:05:23.835335] 1023 In the final outcome, I want to process the list with respect to column 2 above with numbers. In the final processed data, I wanted to have count of unique numbers (even if the occurrence is just once) from column 2 and add it in a new column in front of number. What I really needed was to have time stamp from last occurrence of duplicate/unique entries from number column. [2020-09-15 09:03:21.935335] 1021 2 [2020-09-15 09:03:25.835335] 1022 2 [2020-09-15 09:05:23.835335] 1023 4
Asked by Neeraj (53 rep)
Sep 16, 2020, 03:59 PM
Last activity: Mar 2, 2025, 08:26 AM