Bash: sort text file by last field value

前端 未结 6 1183
自闭症患者
自闭症患者 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 14:45

    I'm going to throw mine in here as an alternative (and I couldn't get awk to work) :)

    sample file:

    Call of Doody                           1322
    Seam the Ripper                         1329
    Mafia Bots 1                            1109
    Chicken Fingers                         1243
    Batup Light                             1221
    Hunter F Tomcat                         1140
    Tober                                   0833
    

    code:

    for i in `sed -e 's/.* \(\d\)*/\1/' file.txt | sort`; do grep $i file.txt; done > file_sort.txt
    

提交回复
热议问题