Bash: sort text file by last field value

前端 未结 6 1172
自闭症患者
自闭症患者 2020-12-24 14:09

I have a text file containing ~300k rows. Each row has a varying number of comma-delimited fields, the last of which is guaranteed numerical. I want to sort the file by this

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 15:00

    Perl one-liner:

    @lines=;foreach(sort{($a=~/.*,(\d+)/)[0]<=>($b=~/.*,(\d+)/)[0]}@lines){print;}
    

提交回复
热议问题