ArticleslgStudy

science

Comm

Comm is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Comm rather than just read about it. In short: comm is a shell command for comparing two files for common and distinct lines. It reads the files as lines of text and outputs text as three columns.

Comm — main illustration
Comm — illustration

Key takeaways

  • Comm belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Comm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Comm from memory before moving on to harder problems.

Reference excerpt

comm is a shell command for comparing two files for common and distinct lines. It reads the files as lines of text and outputs text as three columns. The first two columns contain lines unique to the first and second file, respectively. The last column contains lines common to both. Columns are typically separated with the tab character. If the input text contains lines beginning with the separator character, the output columns can become ambiguous. For efficiency, standard implementations of comm expect both input files to be sequenced in the same line collation order, sorted lexically. The sort command can be used for this purpose. The comm algorithm makes use of the collating sequence of the current locale. If the lines in the files are not both collated in accordance with the current locale, the result is undefined. The command is specified in the POSIX standard. It has been widely available on Unix-like operating systems since the mid to late 1980s. Originally implemented by Lee E. McMahon, the command first appeared in Version 4 Unix. The version in GNU coreutils was written by Richard Stallman and David MacKenzie.

Example

This shows that both files have one banana, but only bar has a second banana. In more detail, the output file has the appearance that follows. Note that the column is interpreted by the number of leading tab characters. \t represents a tab character and \n represents a newline (Escape character#Programming and data formats).

Limits Up to a full line must be buffered from each input file during line comparison, before the next output line is written. Some implementations read lines with the function readlinebuffer() which does not impose any line length limits if system memory suffices. Other implementations read lines with the function fgets(). This function requires a fixed buffer. For these implementations, the buffer is often sized according to the POSIX macro LINE_MAX.

Comparison to diff Although also a file comparison command, diff reports significantly different information than comm. In general, diff is more powerful than comm. The simpler comm is best suited for use in scripts. The primary distinction between comm and diff is that comm discards information about the order of the lines prior to sorting. A minor difference between comm and diff is that comm will not try to indicate that a line has changed between the two files; lines are either shown in the "from file #1", "from file #2", or "in both" columns. This can be useful if one wishes two lines to be considered different even if they only have subtle differences. Unlike for diff, the exit code of comm does not indicate whether the files match. As is typical, 0 indicates success, and other positive values indicate an error.

See also Comparison of file comparison tools List of POSIX commands cmp (Unix) – File comparison command cut (Unix) – Shell command for extracting sections of text files

References

External links

comm: select or reject lines common to two files – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group comm(1) – Plan 9 Programmer's Manual, Volume 1 comm(1) – Inferno General commands Manual

Illustrations

Comm illustration

Worked examples

Example 1 — a first encounter with Comm

Start with the simplest possible case. Write down what Comm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Comm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Comm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Comm

In research
Comm appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Comm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Comm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Free file comparison tools, Inferno (operating system) commands, Plan 9 commands, so understanding it makes those chapters shorter.
In everyday life
Look for Comm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Comm” →

How to study Comm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Comm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Comm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Comm in simple terms?

comm is a shell command for comparing two files for common and distinct lines. It reads the files as lines of text and outputs text as three columns.

Why does Comm matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Comm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Comm.

Tags

  • Free file comparison tools
  • Inferno (operating system) commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities

Keep exploring