Shell之文本排序命令
Shell之文本排序命令
😄 Written by Zak Zhu
学习python风格, 优雅规范书写shell代码
参考
- RHCE培训(RH033-unit8)
- 马哥linux视频
- zenghui08/Linux sort命令的几个细节问题(https://blog.csdn.net/zenghui08/article/details/7938975)
- wajika/LC_ALL=C的含义(http://www.cnblogs.com/wajika/p/6592659.html)
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
细节注意:
- 注意sort命令这样(
sort test > test)是没办法将排序好的标准输出重定向到原文件的 - 正确的使用方法是
sort test -o test
实例详解:
-
sort -t":" -k3,3 -rn passwd![1]()
-
sort -uf test![2]()
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
常用组合:
-
sort test | uniq -i![4]()
-
sort test | uniq -c![5]()





浙公网安备 33010602011771号