Comm
Template:Short description {{#invoke:other uses|otheruses}} Template:For Template:More footnotes Template:Lowercase title {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other The Template:Mono command in the Unix family of computer operating systems is a utility that is used to compare two files for common and distinct lines. Template:Mono is specified in the POSIX standard. It has been widely available on Unix-like operating systems since the mid to late 1980s.
HistoryEdit
Written by Lee E. McMahon, Template:Mono first appeared in Version 4 Unix.<ref name="reader">Template:Cite tech report</ref>
The version of Template:Mono bundled in GNU coreutils was written by Richard Stallman and David MacKenzie.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
UsageEdit
Template:Mono reads two files as input, regarded as lines of text. Template:Mono 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 Template:Mono.
Columns are typically distinguished with the Template:Mono character. If the input files contain lines beginning with the separator character, the output columns can become ambiguous.
For efficiency, standard implementations of Template:Mono 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 Template:Mono 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.
Return codeEdit
Unlike Template:Mono, the return code from Template:Mono 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.
ExampleEdit
<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).
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 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 diffEdit
In general terms, Template:Mono is a more powerful utility than Template:Mono. The simpler Template:Mono is best suited for use in scripts.
The primary distinction between Template:Mono and Template:Mono is that Template:Mono discards information about the order of the lines prior to sorting.
A minor difference between Template:Mono and Template:Mono is that Template:Mono 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 optionsEdit
Template:Mono has command-line options 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.
LimitsEdit
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 Template:Mono which does not impose any line length limits if system memory suffices.
Other implementations read lines with the function Template:Mono. This function requires a fixed buffer. For these implementations, the buffer is often sized according to the POSIX macro Template:Mono.
See alsoEdit
- Comparison of file comparison tools
- List of Unix commands
- cmp (Unix) – character oriented file comparison
- cut (Unix) – splitting column-oriented files
ReferencesEdit
External linksEdit
Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands