group by 'last' value in bash

后端 未结 4 1292
借酒劲吻你
借酒劲吻你 2021-01-26 06:48

I have a two-column file:

1,112
1,123
2,123
2,124
2,144
3,158
4,123
4,158
5,123

I need to know last column2 value for each column1:

<         


        
4条回答
  •  攒了一身酷
    2021-01-26 07:33

    This is pretty similar to @Sundeep's solution but here it goes:

    $ tac file|uniq -w 1|tac
    1,123
    2,144
    3,158
    4,158
    5,123
    

    ie. reverse the record order with cat, uniq outputs based on the first character only and then the order is reversed again.

提交回复
热议问题