How to make use of comm command in Linux
The comm command is utilized in Linux to match other recordsdata, this command compares each line of the recordsdata and presentations the original traces and commonplace traces of the recordsdata in separate columns. The want for comparability of recordsdata most commonly happens to the programmers; after they wish to in finding out the adjustments made in this system over the years.
In this write-up, we’re going to provide an explanation for the usage of the comm command in Linux with an in depth clarification.
How to make use of the comm command in Linux
The comm command can be utilized to match two recordsdata line by way of line, the overall syntax of the use of the comm command:
$ comm [option] FILE_NAME1 FILE_NAME2
The above command syntax will show the lead to 3 columns; the primary column will show the original traces of the file1, the second one column will show the original traces of the file2, and the 3rd column will show the average traces of each recordsdata.
We too can use some choices along side the comm command; some repeatedly used choices are:
Options | Explanation |
-1 | It won’t show the primary column of the end result, which comprises the original traces of the file1 |
-2 | It won’t show the second one column of the end result, which comprises the original traces of the file2 |
-3 | It won’t show the 3rd column of the end result, which comprises the average traces of each recordsdata; file1 and file2 |
–check-order | It will test the entire traces of each recordsdata are correctly looked after or now not |
–nocheck-order | It won’t test the sorting order and simply show the consequences |
–assist | It will display a assist message suggested and can go out |
–model | It will display the model of the ideas and exits |
–complete | It will show the whole choice of traces found in every column of the end result |
-z, –zero-delimiter | It will show the recordsdata one at a time as a substitute of the columns; the worth of 0 delimiters is null |
–output-delimiter=[any character] | It will change the “spaces” within the effects by way of the use of the nature you wish to have to position there |
To perceive these types of choices, we can imagine two textual content recordsdata with the identify; mytestfile1.txt and mytestfile2.txt, whose contents can also be displayed the use of the instructions:
First, we can examine each recordsdata the use of the comm command with none choices, for this goal, we need to use the command:
$ comm mytestfile1.txt mytestfile2.txt
As we all know, the comm command is acceptable at the looked after recordsdata, and the given recordsdata within the command don’t seem to be looked after so it generated the “files not sorted” warnings, to take away those feedback, we can use the “–nocheck-order” flag, which can forget about checking the sorting order and show the consequences:
$ comm –nocheck-order mytestfile1.txt mytestfile2.txt
In the above symbol, we now have marked 3 columns for a greater working out of the consequences, the primary column displayed the original traces of mytestfile1.txt which is best “Fedora”, the second one column displayed the original traces of mytestfile2.txt which is best “Debian”, and the final column displayed the average traces of each recordsdata. If we need to show column 1 (distinctive traces of mytestfile1.txt) and column 3 (commonplace traces of each recordsdata), we can suppress column 2 by way of the use of the “-2” flag:
$ comm -2 –nocheck-order mytestfile1.txt mytestfile2.txt
Likewise, we will suppress each column 1, column 2, and show best column 3 (containing the average traces of each recordsdata) by way of working the command:
$ comm -12 –nocheck-order mytestfile1.txt mytestfile2.txt
The output displayed best the 3rd column of the end result, in an effort to in finding out the whole choice of traces of every column, use the command:
$ comm –total –nocheck-order mytestfile1.txt mytestfile2.txt
To test whether or not the sorting order of each recordsdata are both in the proper order or now not, execute the comm command the use of the “–check-order” flag:
$ comm –check-order mytestfile1.txt mytestfile2.txt
The effects display that report 1 isn’t in looked after order for the reason that names of the recordsdata don’t seem to be organized alphabetically both in ascending order or descending order, in a similar way, the “–zero-delimiter” flag is used:
$ comm –zero-terminated mytestfile1.txt mytestfile2.txt
Likewise, we will use the “–output-delimiter=** ” with the comm command to exchange the distance with “star (*)”:
$ comm –output-delimiter=** –nocheck-order mytestfile1.txt mytestfile2.txt
To test the model of the comm command:
If you wish to have to understand extra in regards to the comm command, you’ll be able to test its handbook by way of the use of the command:
Conclusion
The comm command is used to match the traces of the looked after recordsdata in Linux, regardless that, there are every other tactics too for evaluating recordsdata such because the diff command and the use of the vim editor. The comm command is simple to make use of and beneficial the place the recordsdata include scripts and just a more practical comparability is wanted. In this write-up, we now have mentioned the comm command and its quite a lot of choices in brief with the assistance of examples.