linux--sort

sort 排序

sort [-bcfMnrtk][源文件][-o 输出文件] 

参  数:
  -b   忽略每行前面开始出的空格字符。
  -c   检查文件是否已经按照顺序排序。
  -f   排序时,忽略大小写字母。
  -M   将前面3个字母依照月份的缩写进行排序。
  -n   依照数值的大小排序。
  -o<输出文件>   将排序后的结果存入指定的文件。
  -r   以相反的顺序来排序。
  -t<分隔字符>   指定排序时所用的栏位分隔字符。
  -k  选择以哪个区间进行排序。

[hyb92@localhost cp_1]$ sort number.txt
1
10
11
19
2
5
[hyb92@localhost cp_1]$ sort -n number.txt
1
2
5
10
11
19
[hyb92@localhost cp_1]$ cp number.txt number_a.txt
[hyb92@localhost cp_1]$ sort -n number_a.txt
1
2
5
10
11
19
[hyb92@localhost cp_1]$ sort -n number_a.txt > number_a.txt
[hyb92@localhost cp_1]$ cat number_a.txt
[hyb92@localhost cp_1]$ sort -n number.txt -o number.txt
[hyb92@localhost cp_1]$ cat number.txt
1
2
5
10
11
19

[hyb92@localhost cp_1]$ sort -k2 facebook.txt
sohu 100 4500
baidu 100 5000
google 110 5000
guge 50 3000
[hyb92@localhost cp_1]$ sort -nk2 facebook.txt
guge 50 3000
baidu 100 5000
sohu 100 4500
google 110 5000

[hyb92@localhost cp_1]$ sort -k1 facebook.txt
baidu 100 5000
google 110 5000
guge 50 3000
sohu 100 4500
[hyb92@localhost cp_1]$ sort -k3 facebook.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000
[hyb92@localhost cp_1]$ sort -nk3 facebook.txt
guge 50 3000
sohu 100 4500
baidu 100 5000
google 110 5000
[hyb92@localhost cp_1]$ sort -nr -k3 facebook.txt
google 110 5000
baidu 100 5000
sohu 100 4500
guge 50 3000

转载于:https://www.cnblogs.com/dreamshe92/p/10279441.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值