sed: add Chinese translation (#12856)

Co-authored-by: K.B.Dharun Krishna <kbdharunkrishna@gmail.com>
This commit is contained in:
千玄子 2024-06-01 16:02:15 +08:00 committed by GitHub
parent 45168b603d
commit c52a72afd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

33
pages.zh/linux/sed.md Normal file
View File

@ -0,0 +1,33 @@
# sed
> 以脚本方式编辑文本。
> 参见:`awk`, `ed`.
> 更多信息:<https://www.gnu.org/software/sed/manual/sed.html>.
- 将所有输入行中出现的 `apple`(基本正则语法)替换为 `mango`(基本正则语法),并将结果打印到 `stdout`
`{{命令}} | sed 's/apple/mango/g'`
- 将所有输入行中出现的 `apple`(扩展正则语法)替换为 `APPLE` (扩展正则语法),并将结果打印到 `stdout`
`{{命令}} | sed -E 's/(apple)/\U\1/g'`
- 用 `mango`(基本正则语法)替换特定文件中出现的所有 `apple`(基本正则语法),并覆盖原文件:
`sed -i 's/apple/mango/g' {{路径/到/文件}}`
- 执行特定的脚本,并将结果打印到 `stdout`
`{{命令}} | sed -f {{路径/到/脚本.sed}}`
- 打印第一行到 `stdout`
`{{命令}} | sed -n '1p'`
- 删除文件第一行:
`sed -i 1d {{路径/到/文件}}`
- 插入新行到文件的第一行:
`sed -i '1i\your new line text\' {{路径/到/文件}}`