File tree 1 file changed +16
-3
lines changed
1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ ifconfig ens32 | sed -n '/inet /p' | sed 's/inet \([0-9.]\+\).*/\1/'
223
223
```
224
224
225
225
### 大小写转换U/L
226
+
226
227
``` shell
227
228
\u : 首字母转换为大写
228
229
\U : 全部转换为大写
@@ -250,14 +251,26 @@ BIN:x:1:1:bin:/bin:/sbin/nologin
250
251
251
252
### 组合多个表达式
252
253
254
+ 1 . 替换文本中的多个字符串:
255
+
253
256
``` 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
+ ```
255
259
256
- 等价于 :
260
+ 2 . 删除文本中的多个行 :
257
261
258
- sed ' 表达式; 表达式'
262
+ ``` shell
263
+ sed -e ' 1d' -e ' /pattern/d' file.txt
259
264
```
260
265
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
+
261
274
### 引用
262
275
263
276
sed表达式可以使用单引号来引用,但是如果表达式内部包含变量字符串,就需要使用双引号。
You can’t perform that action at this time.
0 commit comments