Shell脚本去重的几种方法实例
2015-07-10 00:00
736 查看
测试文件
[root@bogon ~]# cat >test jason jason jason fffff jason
按 Ctr + D保存
1、sort -u
[root@bogon ~]# sort -u test fffff jason
2、uniq
[root@bogon ~]# uniq test jason fffff jason
由此可见,uniq需要先排序后才能去重
3、sort、管道和uniq结合运用
去除重复并保留一份重复的数据
[root@bogon ~]# sort test|uniq fffff jason
去除所有重复的行(不保留重复的行),并计算行数
[root@bogon ~]# sort test|uniq -uc 1 fffff
找出所有重复的行,并计算行数
[root@bogon ~]# sort test|uniq -dc 4 jason
根据某个字段去重
将原有数据改为
[root@bogon ~]# more test jason 1 jason 2 jason 1 fffff 2 jason 3 [root@bogon ~]# sort -k 1,1 -u test fffff 2 jason 1
man sort查看sort的用法,-k参数是这么描述的:
-k, --key=POS1[,POS2] start a key at POS1 (origin 1), end it at POS2 (default end of line)
也就是说-k哪几个列进行排序,pos1是开始列,pos2是结束列
相关文章推荐
- Shell中eval的用法示例
- 一个简单的MySQL备份Shell脚本
- calabash-android 链接整理
- iOS Automated Testing With Calabash, Cucumber
- dumpstate uid 由root-->shell
- shell 脚本运行权限
- linux shell脚本攻略 学习笔记3 -- 第三章 以文件之名
- Shell脚本编程入门(一)
- Shell脚本编程入门(一)
- Shell脚本编程入门(一)
- Shell脚本编程入门(一) 分类: 学习笔记 linux ubuntu 2015-07-09 21:06 29人阅读 评论(0) 收藏
- Powershell 通过POP3接收邮件
- Powershell 操作SQL Server
- Powershell 的自动部署
- [批处理教程之Shell]002.Linux 常用命令大全
- 利用IShellExecuteHook接口对程序监控
- bash: mysql: command not found
- [转] Makefile中调用Shell
- /etc/profile与/etc/bashrc、交互式与非交互式、login与non-login shell的区别
- [转] shell文本字符串处理