Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the comm command of linux to compare two sequenced files

Shulou Source: shulou.com Published: 2022-06-02 18:59:29 09月28日 Update

This article mainly introduces the use of linux comm command to compare two ordered files, the article is very detailed, has a certain reference value, interested friends must read it!

The comm command will compare the differences between the two sorted files in a column and display the results. If no parameters are specified, the results will be divided into three lines: the first line is only the column that appeared in the first file, the second line is the column that only appeared in the second file, and the third line is the column that appeared in both the first and second files. If the file name given is "-", the comm instruction reads the data from the standard input device.

Syntax format: [parameters] [File 1] [File 2]

-1 does not show columns that appear only in the first file-2 does not show columns that appear only in the second file-3 does not show columns that appear only in the first and second files-help online help-version displays version information

Reference example

Compare the files filename1.txt and filename2.txt:

[root@linuxcool ~] # comm filename1.txt filename2.txt

To print the intersection of two files, you need to delete the first and second columns:

[root@linuxcool] # comm filename1.txt filename2.txt-1-2

Print out different lines in the two files, and you need to delete the third column:

[root@linuxcool ~] # comm filename1.txt filename2.txt-3 | sed's / ^\ tUnigram'

Compared to the difference set of filename2.txt,filename1.txt:

[root@linuxcool] # comm filename1.txt filename2.txt-2-3

Compared to the difference set of filename1.txt,filename2.txt:

[root@linuxcool] # comm filename2.txt filename1.txt-2-3 above is to use linux's comm command to compare all the contents of two sequenced files. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: File two command content parameter difference is in result reference help same intersection value information interest online help example boy partner difference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Apple Docker MySQL