2018-11-16 13:39:35 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
author: Domenico Votta
|
|
|
|
category-page: advanced
|
|
|
|
category-title: Advanced commands
|
|
|
|
tags: compare sorted files
|
|
|
|
title: comm
|
|
|
|
---
|
2018-11-16 19:47:01 +00:00
|
|
|
The <code>comm</code> is a command that compares two sorted files
|
|
|
|
line by line and writes the output: the lines that are in common and the lines that are unique.<br>
|
2018-11-16 13:39:35 +00:00
|
|
|
|
|
|
|
Here we have two files named <code>example1.txt</code> and
|
|
|
|
<code>example2.txt</code> that contain 5 elements, to test this command:<br>
|
|
|
|
|
|
|
|
<code>example1.txt</code>
|
|
|
|
{% highlight bash linenos %}
|
|
|
|
Icecream
|
|
|
|
Chocolate
|
|
|
|
Cake
|
|
|
|
Candy
|
|
|
|
Biscuit
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
<code>example2.txt</code>
|
|
|
|
{% highlight bash linenos %}
|
|
|
|
Bread
|
|
|
|
Chocolate
|
|
|
|
Tomato
|
|
|
|
Candy
|
|
|
|
Pizza
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
The syntax command is:
|
2018-11-16 19:47:01 +00:00
|
|
|
<pre>
|
|
|
|
comm [flag][file1] [file2]
|
|
|
|
</pre>
|
2018-11-16 13:39:35 +00:00
|
|
|
|
|
|
|
<pre>
|
|
|
|
comm example1.txt example2.txt
|
2018-11-16 19:47:01 +00:00
|
|
|
Icecream
|
|
|
|
Chocolate
|
|
|
|
Cake
|
|
|
|
Tomato
|
|
|
|
Candy
|
|
|
|
Biscuit
|
|
|
|
Pizza
|
2018-11-16 13:39:35 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
<ul>
|
|
|
|
<li>The elements of the first file have less indentation.</li>
|
|
|
|
<li>The elements of the second file have some more indentation.</li>
|
|
|
|
<li>The elements in common have even more indentation than those of the second file.</li>
|
|
|
|
</ul>
|
2018-11-16 13:39:35 +00:00
|
|
|
|
2018-11-16 19:47:01 +00:00
|
|
|
<h3>Flags</h3>
|
2018-11-16 13:39:35 +00:00
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li> <b>-1</b>: supress column 1</li>
|
|
|
|
<li> <b>-2</b>: supress column 2</li>
|
|
|
|
<li> <b>-3</b>: supress column 3</li>
|
|
|
|
</ul>
|