> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man1/comm.1.md).

# comm.1

`comm` — 选择或拒绝两个文件中共同的行

## 名称

`comm`

## 概要

`comm [-123i] file1 file2`

## 描述

`comm` 实用程序读取 `file1` 和 `file2`（两者应已按词法排序），并产生三列文本输出：仅在 `file1` 中的行；仅在 `file2` 中的行；以及两个文件中都有的行。

文件名 \`\`-'' 表示标准输入。

以下选项可用：

**`-1`** 禁止打印第 1 列，即仅在 `file1` 中的行。

**`-2`** 禁止打印第 2 列，即仅在 `file2` 中的行。

**`-3`** 禁止打印第 3 列，即两个文件中共同的行。

**`-i`** 行比较时不区分大小写。

每列前面将附加若干制表符，数量等于正在打印的、编号小于该列的列数。例如，如果第 2 列被禁止打印，则第 1 列打印的行前面没有任何制表符，而第 3 列打印的行前面有一个制表符。

`comm` 实用程序假设文件已按词法排序；所有字符都参与行比较。

## 环境变量

`LANG`、`LC_ALL`、`LC_COLLATE` 和 `LC_CTYPE` 环境变量会影响 `comm` 的执行，如 [environ(7)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man7/environ.7.md) 所述。

## 退出状态

`comm` 实用程序成功时退出值为 0，发生错误时大于 0。

## 实例

假设有一个名为 `example.txt` 的文件，内容如下：

```sh
a
b
c
d
```

显示仅在 `example.txt` 中的行、仅在标准输入中的行以及共同的行：

```sh
$ echo -e "B\nc" | comm example.txt -
        B
a
b
                c
d
```

仅显示共同行，进行不区分大小写的比较：

```sh
$ echo -e "B\nc" | comm -1 -2 -i example.txt -
b
c
```

## 参见

[cmp(1)](/man/man1/cmp.1.md), [diff(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/diff.1.md), [sort(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/sort.1.md), [uniq(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/uniq.1.md)

## 标准

`comm` 实用程序符合 ISO/IEC 9945-2:1993 ("POSIX.2") 规范。

`-i` 选项是对 POSIX 标准的扩展。

## 历史

`comm` 命令首次出现于 Version 4 AT\&T UNIX。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man1/comm.1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
