Bash: sort text file by last field value

前端 未结 6 1184
自闭症患者
自闭症患者 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:05

    Python one-liner:

    python -c "print ''.join(sorted(open('filename'), key=lambda l: int(l.split(',')[-1])))"
    

提交回复
热议问题