![linux comm命令](https://i-blog.csdnimg.cn/blog_migrate/e349fa91232689316cc559db85b69f7c.png)
linux comm命令
Linux have a lot of tools to compare files. These tools provides a lot of powerful features to meet user needs. But sometimes just simple comparison is enough for some users. comm
is a tool for this purpose . Comm only compare files and shows differences in a visual manner.
Linux有很多工具可以比较文件。 这些工具提供了许多强大的功能来满足用户需求。 但是有时候,对于某些用户而言,简单的比较就足够了。 comm
是用于此目的的工具。 Comm仅比较文件并以可视方式显示差异。
句法 (Syntax)
We will use following syntax for comm
command.
我们将对comm
命令使用以下语法。
comm [OPTION]... FILE1 FILE2
帮帮我 (Help)
$ comm --help
![Help](https://i-blog.csdnimg.cn/blog_migrate/ff8de7e4d8cc52eba5a5fce2f1597bd4.png)
相比(Compare)
We will simply compare two files those have same and different lines. We just need to provide file names to the comm command. Here is our files.
我们将简单比较两个具有相同和不同行的文件。 我们只需要为comm命令提供文件名即可。 这是我们的文件。
a.txt (a.txt)
test
pof
apple
banana
b.txt (b.txt)
test
ok
apple
banana
lemon
Now we issue the command like below.
现在,我们发出如下命令。
$ comm a.txt b.txt
![Compare](https://i-blog.csdnimg.cn/blog_migrate/a8552923b1aadb72f640530a81856093.png)
As we can see the differences ok
and lemon
are printed in required column.
正如我们所看到的,“ ok
和“ lemon
的区别被打印在必填列中。
检查订单 (Check Order)
In previous example we see that there are some information about unsorted columns. comm command automatically checks the order of the provided text file. This can be disabled with --nocheck-order
parameter.
在前面的示例中,我们看到一些有关未排序列的信息。 comm命令自动检查提供的文本文件的顺序。 可以使用--nocheck-order
参数禁用此功能。
$ comm --nocheck-order a.txt b.txt
![Do Check Order](https://i-blog.csdnimg.cn/blog_migrate/f269ea787973673433a56f1bf2b498a6.png)
抑制列(Suppress Columns)
Columns can be suppressed with the suppress feature. We just need to provide column number to suppress like -1
, -2
, -3
可以使用抑制功能抑制列。 我们只需要提供列号来抑制-1
, -2
, -3
- -1 suppress column 1 (lines unique to FILE1) -1抑制列1(FILE1独有的行)
- -2 suppress column 2 (lines unique to FILE2) -2取消第2列(FILE2独有的行)
- -3 suppress column 3 (lines that appear in both files) -3取消第3列(两个文件中均显示行)
$ comm -1 a.txt b.txt
![Suppress Columns](https://i-blog.csdnimg.cn/blog_migrate/7c3bcc5a3822ae6f5e15ed31782cf7e3.png)
翻译自: https://www.poftut.com/compare-files-comm-command-linux/
linux comm命令