> 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/paste.1.md).

# paste.1

`paste` — 合并文件中对应或后续的行

## 名称

`paste`

## 概要

`paste [-s] [-d list] file ...`

## 描述

`paste` 实用程序将给定输入文件中对应的行连接起来，将除最后一个文件外的所有文件的换行符替换为单个制表符，并将结果行写入标准输出。如果某个输入文件已到达文件末尾而其他输入文件仍有数据，则将该文件视为源源不断的空行。

选项如下：

**`-d`** `list` 使用一个或多个提供的字符来替换换行符，而不是默认的制表符。`list` 中的字符循环使用，即当 `list` 用完时，会重新使用 `list` 中的第一个字符。此过程持续到显示完最后一个输入文件的行（默认操作）或每个文件的最后一行（使用 `-s` 选项）为止，此时 `paste` 重新从 `list` 的开头开始选取字符。`list` 中还可以使用以下特殊字符：

`\n` 换行字符

`\t` 制表字符

`\\` 反斜杠字符

`\0` 空字符串（不是空字符）。

任何其他前面带反斜杠的字符等同于该字符本身。

**`-s`** 按命令行顺序连接每个单独输入文件的所有行。除非 `-d` 选项另有指定，否则每个输入文件中除最后一行外的每一行的换行符都替换为制表符。

如果为一个或多个输入文件指定了 ‘`-`’，则使用标准输入；标准输入按每个 ‘`-`’ 实例循环地每次读取一行。

## 退出状态

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

## 实例

以三列形式列出当前目录中的文件：

```sh
ls | paste - - -
```

将文件中的行对组合为单行：

```sh
paste -s -d '\t\n' myfile
```

为文件中的行编号，类似于 nl(1)：

```sh
sed = myfile | paste - -
```

创建名为 `bin` 的目录的冒号分隔列表，适用于 `PATH` 环境变量：

```sh
find / -name bin -type d | paste -s -d : -
```

## 参见

[cut(1)](/man/man1/cut.1.md), lam(1)

## 标准

`paste` 实用程序预期与 IEEE Std 1003.2 ("POSIX.2") 兼容。

## 历史

`paste` 命令首次出现于 AT\&T System III UNIX，并自 4.3BSD-Reno 起可用。

## 作者

最初的 Bell Labs 版本由 Gottfried W. R. Luderer 编写，BSD 版本由 Adam S. Moskowitz 和 Marciano Pitargue 编写。


---

# 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/paste.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.
