forked from tldr-pages/tldr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\新行内容\' {{文件路径}}` |