Skip to content

Commit 8b3e8f6

Browse files
authored
doc: Update sed.md (#503)
1 parent 023ce79 commit 8b3e8f6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Diff for: command/sed.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ ifconfig ens32 | sed -n '/inet /p' | sed 's/inet \([0-9.]\+\).*/\1/'
223223
```
224224

225225
### 大小写转换U/L
226+
226227
```shell
227228
\u: 首字母转换为大写
228229
\U: 全部转换为大写
@@ -250,14 +251,26 @@ BIN:x:1:1:bin:/bin:/sbin/nologin
250251

251252
### 组合多个表达式
252253

254+
1. 替换文本中的多个字符串:
255+
253256
```shell
254-
sed '表达式' | sed '表达式'
257+
sed -e 's/old_string/new_string/g' -e 's/another_old_string/another_new_string/g' file.txt
258+
```
255259

256-
等价于
260+
2. 删除文本中的多个行
257261

258-
sed '表达式; 表达式'
262+
```shell
263+
sed -e '1d' -e '/pattern/d' file.txt
259264
```
260265

266+
3. 在文本中插入多个行:
267+
268+
```shell
269+
sed -e '1i\inserted_line1' -e '2i\inserted_line2' file.txt
270+
```
271+
272+
其中,-e 表示指定一个表达式,多个表达式之间用 -e 分隔。每个表达式可以是一个 sed 命令,例如 s、d、i 等。
273+
261274
### 引用
262275

263276
sed表达式可以使用单引号来引用,但是如果表达式内部包含变量字符串,就需要使用双引号。

0 commit comments

Comments
 (0)