首页 > 编程语言 > 详细

Shell之文本排序命令

时间:2019-10-01 15:26:59      阅读:118      评论:0      收藏:0      [点我收藏+]

Shell之文本排序命令

?? Written by Zak Zhu

学习python风格, 优雅规范书写shell代码

参考

wc命令

Word Count

wc -l       # line count

sort命令

Sorts text to STDOUT - original file unchanged

sort [OPTION]... [FILE]...
Options:
    -r, --reverse
    -n, --numeric-sort 
    -f, --ingnore-case
    -u, --unique                                
    -t "SEP" -k START,END  
    -o, --output

细节注意:

  1. 注意sort命令这样(sort test > test)是没办法将排序好的标准输出重定向到原文件的
  2. 正确的使用方法是sort test -o test

实例详解:

  1. sort -t":" -k3,3 -rn passwd

    技术分享图片

  2. sort -uf test

    技术分享图片

uniq命令

Note: uniq dose not detect repeated lines unless they are adjacent. You may want to sort the input first, or use sort -u without uniq !!

技术分享图片

uniq - report or omit repeated lines

常用组合:

  1. sort test | uniq -i

    技术分享图片

  2. sort test | uniq -c

    技术分享图片

Shell之文本排序命令

原文:https://www.cnblogs.com/zakzhu/p/11615435.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!