使用sort命令对内容进行排序
扫码查看 原文链接 : https://blog.lmlphp.com/tutorial/1/SHELL/item/6/Use_sort_command_to_sort_the_contents 来自 : LMLPHP后院![]()
sort 命令默认按照 ASCII 字符顺序排序。如下示例:
$ echo " one \n two \n three" | sort one three two $ echo "4\n1\n3\n100" | sort 1 100 3 4
使用 -n 指定按照数字排序,如下示例:
echo "4\n1\n3\n100" | sort -n 1 3 4 100
使用 -M 参数可以支持三个字母的月份进行排序,-r 参数倒序排列。
常用例子,设置分隔符,指定以第几个字段进行排序:
$ sort -t':' -k 3 -n /etc/passwd