> For the complete documentation index, see [llms.txt](https://huataihuang.gitbook.io/cloud-atlas-draft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://huataihuang.gitbook.io/cloud-atlas-draft/develop/shell/sed_awk/sed_-i_option_fail_on_mac.md).

# Mac平台sed命令使用-i参数失败及解决方法

在macOS上使用 `sed -i` 命令修订文件会出现报错

```bash
sed: 1: "app_list": command a expects \ followed by text
```

在macOS上使用 `-i` 参数需要提供一个备份文件的扩展名，并使用 `-e` 修订文件:

```bash
sed -i'.original' -e 's/old_link/new_link/g' File1.txt
```

则被修改的文件 `File1.txt` ，会生成一个 `File1.txt.original` 的备份文件，并且原文件 `File1.txt` 就修订好了。不过，这个 `-i -e` 参数需要OS X 10.9+以上版本，早期OS X版本不支持。并且，这个参数组合在Linux上也不能工作。

比较简单的方法还是在macOS上安装GNU sed工具来（通过homebrew):

```bash
brew install gnu-sed
```

然后使用命令 `/usr/local/bin/gsed` 来处理。

## 参考

* [sed command with -i option failing on Mac, but works on Linux](https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux)


---

# 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://huataihuang.gitbook.io/cloud-atlas-draft/develop/shell/sed_awk/sed_-i_option_fail_on_mac.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.
