# 移除换行

经常需要ssh到服务器上执行一系列命令，但是每个命令输出以后会换行，对于一些搜集信息，想实现每个主机返回收据都在一行，以便后期过滤处理。

解决思路主要有：

* `echo`命令使用`-n`参数，则可以不换行
* `echo -n $(执行的命令)`则通过`echo -n`方式打印结果就不会换行
* 通过`tr`命令去除和

```
tr -d "\n\r" < yourfile.txt
```

> unix环境，window环境

## 参考

* [Why does bash remove \n in $(cat file)?](https://askubuntu.com/questions/121866/why-does-bash-remove-n-in-cat-file)


---

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