10

How to Sort by Length of String Followed by Alphabetical Order

 3 years ago
source link: https://happy123.me/blog/2020/08/17/how-to-sort-by-length-of-string-followed-by-alphabetical-order/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Sort by Length of String Followed by Alphabetical Order

Aug 17th, 2020 | 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

Posted by brain-zhang

Aug 17th, 2020tools

« xargs sh -c skipping the first argument


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK