SORT command is the most commonly used command for sorting files in linux. It is a command line utility that can be used to sort files according to various criteria, like alphabetically, numerically and chronologically.
成都创新互联为您提适合企业的网站设计 让您的网站在搜索引擎具有高度排名,让您的网站具备超强的网络竞争力!结合企业自身,进行网站设计及把握,最后结合企业文化和具体宗旨等,才能创作出一份性化解决方案。从网站策划到成都网站设计、网站制作, 我们的网页设计师为您提供的解决方案。
Sort command provides many options/flags to sort files in different manners. It also accepts options to sort in reverse order, to ignore differences between folded and upper/lower cases and to discard empty lines.
Example 1:
Sort Alphabetically
The below example shows how to sort a file containing a list of words in alphabetic order.
$sort words.txt
apple
banana
cat
dog
Example 2:
Sort Numerically
The below example shows how to sort a file containing a list of numbers in a numerical order.
$sort -n numbers.txt
1
2
3
4
Example 3:
Sort in Reverse order
The below example shows how to sort a file containing a list of words in reverse alphabetical order.
$sort -r words.txt
dog
cat
banana
apple
Example 4:
Ignore Case differences
The below example shows how to sort a file containing a list of words ignoring their case differences.
$sort -f words.txt
apple
banana
Cat
dog
Example 5:
Discard empty lines
The below example shows how to sort a file containing a list of words and dropping empty lines in the output.
$sort -z words.txt
apple
banana
cat
dog
In conclusion, the sort command is a useful utility to arrange files in Linux according to various criteria. It provides many options which can be used to sort files with different conditions and produce expected result. With the help of these examples, you can easily understand more about sorting files using this command.
成都网站建设选创新互联(☎:028-86922220),专业从事成都网站制作设计,高端小程序APP定制开发,成都网络营销推广等一站式服务。
当前标题:深入了解Linux命令中的排序方法(linux命令排序)
转载注明:http://www.gawzjz.com/qtweb2/news36/22386.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联