shell脚本之正则表达式(四)---sort与uniq工具
2019-10-11 17:18
1016 查看
sort 工具
sort 是一个以行为单位对文件内容进行排序的工具,也可以根据不同的数据类型来排序。
sort 语法
sort [选项] 参数
sort常用选项
-f:忽略大小写 -b:忽略每行前面的空格 -M:按照月份进行排序 -n:按照数字进行排序 -r:反向排序 -u:表示相同的数据仅显示一行(去除不连续的重复) -t:指定分隔符,默认使用[Tab]键分隔 -o <输出文件>:将排序后的结果转存至指定文件 -k:指定排序区域
范例演示
将/etc/passwd 文件中第三列进行排序,并将输出内容保存至user.txt 文件中
[root@localhost ~]# sort -t ':' -k 3 /etc/passwd -o user.txt //将/etc/passwd 文件中第三列进行排序,并将输出内容保存至user.txt 文件中 [root@localhost ~]# cat user.txt //查看文件 root:x:0:0:root:/root:/bin/bash czt:x:1000:1000:czt:/home/czt:/bin/bash ccc:x:1001:1001::/home/ccc:/bin/bash ......
uniq 工具
Uniq 工具在 Linux 系统中通常与 sort 命令结合使用,用于报告或者忽略文件中的重复行。
uniq语法
uniq [选项] 参数
uniq常用选项
-c:进行计数 -d:仅显示重复行 -u:仅显示出现一次的行(仅去除连续的重复)
范例演示
删除 testfile 文件中的重复行,并在行首显示该行重复出现的次数
[root@localhost ~]# vim testfile Linux 10 Linux 20 Linux 30 Linux 30 Linux 30 CentOS 6.5 CentOS 6.5 CentOS 6.5 CentOS 7.3 CentOS 7.3 CentOS 7.3 [root@localhost ~]# uniq -c testfile //*删除 testfile 文件中的重复行,并在行首显示该行重复出现的次数 1 Linux 10 1 Linux 20 3 Linux 30 3 CentOS 6.5 3 CentOS 7.3
相关文章推荐
- 《Unix Shell编程》第四章学习笔记--工具[ed、正则表达式、cut、sed、paste、tr、grep、sort、uniq](思维导图)
- shell脚本之正则表达式(三)---awk工具
- 正则表达式及grep、sed、awk、cut、sort、uniq工具
- 《Unix Shell编程》第四章练习题及答案——工具[ed、正则表达式、cut、sed、paste、tr、grep、sort、uniq]
- Linux下正则表达式以及几种工具:grep,sed,awk,cut,sort,uniq的简单应用
- shell脚本编程4:正则表达式
- shell脚本学习:循序渐进程序选择流与正则表达式
- shell脚本编程(一)正则表达式
- shell脚本正则表达式
- shell 脚本-正则表达式
- 正则表达式和Shell脚本。
- 学习笔记之Shell脚本学习指南 & sed与awk & 正则表达式
- linux命令行与shell脚本大全_第十九章_正则表达式
- shell脚本——正则表达式
- shell脚本系列-正则表达式介绍
- shell 脚本 正则表达式通配符之 "[]" [大三TJB_708]
- shell脚本编写之常用基础命令(diff、patch、cut、sort、uniq、&&与||、test、tr)
- Linux--shell脚本之正则表达式
- Linux--shell脚本之正则表达式
- 鸟哥Linux私房菜笔记(二):正则表达式、shell脚本