Think before you speak, read before you think.

sort命令

对 /etc/hosts 文件排序默认是按字符串

如果对 ip 排序

sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n /etc/hosts
sort -t . +0 -1n +1 -2n +2 -3n +3 -4n /etc/hosts

发现一个简单方法

sort -V /etc/hosts

排序命令Sort
sort -k 2,2
-k, –key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of line)


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *