# 替换多个空格成为一个空格

很多时候需要压缩一行文本中不断变化的空白符号，将多个空白改成一个空白，或者替换成分隔逗号 `,`

举例:

```bash
"too         many       spaces."
```

替换成

```bash
"too many spaces."
```

解决方法是使用 `tr -s` 命令：

```
-s, --squeeze-repeats
       replace each sequence of a repeated character that is listed  in
       the last specified SET, with a single occurrence of that charac‐
       ter
```

在我的实践案例中，我需要把文本中的多个 `TAB` 替换成一个 `,` ，以便输出 `.csv` 文件，也采用上述方法

## 参考

* [How to replace multiple spaces with a single space using Bash?](https://stackoverflow.com/questions/50259869/how-to-replace-multiple-spaces-with-a-single-space-using-bash)


---

# Agent Instructions: 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:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/develop/shell/bash/replace_multiple_spaces_with_a_single_space.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
