Living a Simple Life is a Happy Life

有饭吃,自由自在,就非常开心

How to Sort by Length of String Followed by Alphabetical Order

| Comments

shell中,多行文本,先按照字母长度排序,相同长度再按照字母序排列;

做了很多次,隔几天就忘,让人绝望:

1
cat /tmp/xxx.txt|sort -u | awk '{print length($0), $0}'  | sort -k2,2n -k1,1n -k3,3 |cut -d" " -f2-|less

Comments