File tree Expand file tree Collapse file tree 1 file changed +36
-4
lines changed Expand file tree Collapse file tree 1 file changed +36
-4
lines changed Original file line number Diff line number Diff line change 66
66
jjj
67
67
```
68
68
69
- 两个文件之间的比较,如果没有排序需要带上` --nocheck-order ` 参数
69
+ 两个文件之间的比较,如果没有排序需要带上` --nocheck-order ` 参数, 没有带上参数将会收到提示,此命令重要之功能在于比较。
70
+
71
+ ``` bash
72
+ comm: 文件2 没有被正确排序
73
+ comm: 文件1 没有被正确排序
74
+ ```
75
+
76
+ 比较结果
70
77
71
78
```
72
79
[root@localhost text]# comm --nocheck-order aaa.txt bbb.txt
86
93
87
94
输出的第一列只包含在aaa.txt中出现的行,第二列包含在bbb.txt中出现的行,第三列包含在aaa.txt和bbb.txt中相同的行。各列是以制表符(\t)作为定界符。
88
95
89
- ** 交集**
96
+ ### 有序比较
97
+
98
+ 有序比较,先通过 sort 将文件内容排序
99
+
100
+ ```
101
+ [root@localhost ~]# sort aaa.txt > aaa1.txt
102
+ [root@localhost ~]# sort bbb.txt > bbb1.txt
103
+ ```
104
+
105
+ 有序比较结果:
106
+
107
+ ```
108
+ [root@localhost ~]# comm aaa1.txt bbb1.txt
109
+ 111
110
+ 222
111
+ aaa
112
+ bbb
113
+ ccc
114
+ ddd
115
+ eee
116
+ hhh
117
+ jjj
118
+ ttt
119
+ ```
120
+
121
+ ### 交集
90
122
91
123
打印两个文件的交集,需要删除第一列和第二列:
92
124
96
128
ccc
97
129
```
98
130
99
- ** 求差**
131
+ ** 求差**
100
132
101
133
打印出两个文件中不相同的行,需要删除第三列:
102
134
115
147
116
148
` sed 's/^\t//' ` 是将制表符` \t ` 删除,以便把两列合并成一列。
117
149
118
- ** 差集 **
150
+ ### 差集
119
151
120
152
通过删除不需要的列,可以得到aaa.txt和bbb.txt的差集:
121
153
You can’t perform that action at this time.
0 commit comments