Skip to content

Commit

Permalink
sed: add Chinese translation
Browse files Browse the repository at this point in the history
  • Loading branch information
zjuyk committed May 29, 2024
1 parent 42fea64 commit bf1e59f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pages.zh/linux/sed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# sed

> 以脚本方式编辑文本。
> 参见:`awk`, `ed`.
> 更多信息:<https://www.gnu.org/software/sed/manual/sed.html>.
- 将所有输入行中出现的 `apple`(基本正则语法)替换为 `mango`(基本正则语法),并将结果打印到 `标准输出`

`{{命令}} | sed 's/apple/mango/g'`

- 将所有输入行中出现的 `apple`(扩展正则语法)替换为 `APPLE` (扩展正则语法),并将结果打印到 `标准输出`

`{{命令}} | sed -E 's/(apple)/\U\1/g'`

-`mango`(基本正则语法)替换特定文件中出现的所有 `apple`(基本正则语法),并覆盖原文件:

`sed -i 's/apple/mango/g' {{文件路径}}`

- 执行特定的脚本,并将结果打印到 `标准输出`

`{{命令}} | sed -f {{sed 脚本路径}}`

- 打印第一行到 `标准输出`

`{{命令}} | sed -n '1p'`

- 删除文件第一行:

`sed -i 1d {{文件路径}}`

- 插入新行到文件的第一行:

`sed -i '1i\新行内容\' {{文件路径}}`

0 comments on commit bf1e59f

Please sign in to comment.