sort,linux,shell命令
来源:互联网 发布:hdmi 网络中控 编辑:程序博客网 时间:2024/06/05 06:38
经常有这样的需求:两个文本文件要求取重复的行或只取不重复的,简单的情况下用sort和uniq来处理是非常方便的:
利用现存两个文件,生成一个新的文件
1. 取出两个文件的并集(重复的行只保留一份)
2. 取出两个文件的交集(只留下同时存在于两个文件中的文件)
3. 删除交集,留下其他的行
1. cat file1 file2 | sort | uniq
2. cat file1 file2 | sort | uniq -d
3. cat file1 file2 | sort | uniq -u
例如:
[zzx@test55 ~]$ cat a
1
2
3
[zzx@test55 ~]$ cat b
23
2
3
4
5
6
排序:
[zzx@test55 ~]$ cat a b|sort
1
2
2
23
3
3
4
5
6
去重(并集):
[zzx@test55 ~]$ cat a b|sort|uniq
1
2
23
3
4
5
6
交集:
[zzx@test55 ~]$ cat a b|sort|uniq -d
2
3
去除交集后的并集
[zzx@test55 ~]$ cat a b|sort|uniq -u
1
23
4
5
6
差集可以用以下两种方法实现:
grep -F -f listb lista -v
sort B B A | uniq -u
Linux shell 排重 大全[待续]
1. sort tt.txt | awk '!a[$1]++'
2. sort -u tt.txt
3. sort tt.txt | uniq -d > tmp.txt
sort tt.txt | uniq -u >> tmp.txt
利用现存两个文件,生成一个新的文件
1. 取出两个文件的并集(重复的行只保留一份)
2. 取出两个文件的交集(只留下同时存在于两个文件中的文件)
3. 删除交集,留下其他的行
1. cat file1 file2 | sort | uniq
2. cat file1 file2 | sort | uniq -d
3. cat file1 file2 | sort | uniq -u
例如:
[zzx@test55 ~]$ cat a
1
2
3
[zzx@test55 ~]$ cat b
23
2
3
4
5
6
排序:
[zzx@test55 ~]$ cat a b|sort
1
2
2
23
3
3
4
5
6
去重(并集):
[zzx@test55 ~]$ cat a b|sort|uniq
1
2
23
3
4
5
6
交集:
[zzx@test55 ~]$ cat a b|sort|uniq -d
2
3
去除交集后的并集
[zzx@test55 ~]$ cat a b|sort|uniq -u
1
23
4
5
6
差集可以用以下两种方法实现:
grep -F -f listb lista -v
sort B B A | uniq -u
Linux shell 排重 大全[待续]
1. sort tt.txt | awk '!a[$1]++'
2. sort -u tt.txt
3. sort tt.txt | uniq -d > tmp.txt
sort tt.txt | uniq -u >> tmp.txt
- sort,linux,shell命令
- LINUX SHELL之SORT命令
- Linux shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令
- Linux Shell之sort命令(转)
- [SHELL]:sort 命令详解
- shell脚本sort命令
- shell sort命令
- sort命令(排序) -- shell
- shell中的sort命令
- shell- sort命令
- 我所知道的.NET异步
- 【Google官方教程】第四课:在UI中显示Bitmap
- android UI 优化系之 使用theme 预加载
- [转]Quartz 2D编程指南(5) – 变换
- 数字签名和数字证书图解
- sort,linux,shell命令
- PNG图像文件结构解析
- 分页的核心思想
- UBuntu下载编译安装内核
- asp.net 使用ajax分页
- MFC画线,要多点一下鼠标,线才出现
- c++将临时对象赋值给引用和指针的不同
- Java 利用反射构造私有数据类型
- 把一个XML字符串转换为一个XML文档对象