Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comm
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Standard UNIX utility for comparing files}} {{Other uses}} {{for|the Portuguese Order of Merit|ComM}} {{more footnotes|date=January 2013}} {{lowercase title}} {{Infobox software | name = comm | logo = | screenshot = Comm-example.png | screenshot size = | caption = Example usage of <code>comm</code> command | author = [[Lee E. McMahon]] | developer = [[AT&T Bell Laboratories]], [[Richard Stallman]], David MacKenzie | released = {{Start date and age|1973|11}} | latest release version = | latest release date = | programming language = [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]]<br />Plan 9: [[MIT License]] | website = }} The {{mono|'''comm'''}} command in the [[Unix]] family of computer [[operating system]]s is a utility that is used to compare two [[computer file|files]] for common and distinct lines. {{Mono|comm}} is specified in the [[POSIX]] standard. It has been widely available on [[Unix-like]] operating systems since the mid to late 1980s.<!-- Case Larsen BSD 1989 (as found in OpenBSD), Richard Stallman and David MacKenzie Gnu 1986 --> ==History== Written by [[Lee E. McMahon]], {{Mono|comm}} first appeared in [[Version 4 Unix]].<ref name="reader">{{cite tech report | first1 = M. D. | last1 = McIlroy | authorlink1 = Doug McIlroy | year = 1987 | url = https://www.cs.dartmouth.edu/~doug/reader.pdf | title = A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971β1986 |series=CSTR | number = 139 | institution = Bell Labs}}</ref> The version of {{mono|'''comm'''}} bundled in [[GNU]] [[coreutils]] was written by [[Richard Stallman]] and David MacKenzie.<ref>{{Cite web|url=https://linux.die.net/man/1/comm|title = Comm(1): Compare two sorted files line by line - Linux man page}}</ref> ==Usage== {{Mono|comm}} reads two files as input, regarded as lines of text. {{Mono|comm}} outputs one file, which contains three columns. The first two columns contain lines unique to the first and second file, respectively. The last column contains lines common to both. This functionally is similar to {{Mono|[[diff]]}}. Columns are typically distinguished with the {{Mono|''<tab>''}} character. If the input files contain lines beginning with the separator character, the output columns can become ambiguous. For efficiency, standard implementations of {{Mono|comm}} expect both input files to be sequenced in the same line [[collation]] order, sorted lexically. The [[sort (Unix)]] command can be used for this purpose. The {{Mono|comm}} algorithm makes use of the collating sequence of the current [[Locale (computer software)|locale]]. If the lines in the files are not both collated in accordance with the current locale, the result is undefined. ==Return code== Unlike {{Mono|diff}}, the return code from {{Mono|comm}} has no logical significance concerning the relationship of the two files. A return code of 0 indicates success, a return code >0 indicates an error occurred during processing. ==Example== <syntaxhighlight lang="console"> $ cat foo apple banana eggplant $ cat bar apple banana banana zucchini $ comm foo bar apple banana banana eggplant zucchini </syntaxhighlight> 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]]). {|class="wikitable" style="text-align:center" ! style="min-width:20px" | !! style="min-width:20px" | 0 !! style="min-width:20px" | 1 !! style="min-width:20px" | 2 !! style="min-width:20px" | 3 !! style="min-width:20px" | 4 !! style="min-width:20px" | 5 !! style="min-width:20px" | 6 !! style="min-width:20px" | 7 !! style="min-width:20px" | 8 !! style="min-width:20px" | 9 |- ! 0 | \t || \t || a || p || p || l || e || \n |- ! 1 | \t || \t || b || a || n || a || n || a || \n |- ! 2 | \t || b || a || n || a || n || a || \n |- ! 3 | e || g || g || p || l || a || n || t || \n |- ! 4 | \t || z || u || c || c || h || i || n || i || \n |} ==Comparison to diff== In general terms, {{Mono|diff}} is a more powerful utility than {{Mono|comm}}. The simpler {{Mono|comm}} is best suited for use in scripts. The primary distinction between {{Mono|comm}} and {{Mono|diff}} is that {{Mono|comm}} discards information about the order of the lines prior to sorting. A minor difference between {{Mono|comm}} and {{Mono|diff}} is that {{Mono|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. ==Other options== '''{{Mono|comm}}''' has [[command-line option]]s to suppress any of the three columns. This is useful for scripting. There is also an option to read one file (but not both) from standard input. ==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 {{Mono|readlinebuffer()}} which does not impose any line length limits if system memory suffices. Other implementations read lines with the function {{Mono|[[fgets]]()}}. This function requires a fixed buffer. For these implementations, the buffer is often sized according to the [[POSIX]] macro {{Mono|LINE_MAX}}. ==See also== * [[Comparison of file comparison tools]] * [[List of Unix commands]] * [[cmp (Unix)]] β character oriented file comparison * [[cut (Unix)]] β splitting column-oriented files ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} * {{man|cu|comm|SUS|select or reject lines common to two files}} * {{man|1|comm|Plan 9}} * {{man|1|comm|Inferno}} {{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} [[Category:Free file comparison tools]] [[Category:Standard Unix programs|Comm]] [[Category:Unix SUS2008 utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite tech report
(
edit
)
Template:Cite web
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:For
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase title
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:More footnotes
(
edit
)
Template:Other uses
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)