Skip to content

Commit

Permalink
doc: Update sed.md (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 25, 2023
1 parent 023ce79 commit 8b3e8f6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions command/sed.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ ifconfig ens32 | sed -n '/inet /p' | sed 's/inet \([0-9.]\+\).*/\1/'
```

### 大小写转换U/L

```shell
\u: 首字母转换为大写
\U: 全部转换为大写
Expand Down Expand Up @@ -250,14 +251,26 @@ BIN:x:1:1:bin:/bin:/sbin/nologin

### 组合多个表达式

1. 替换文本中的多个字符串:

```shell
sed '表达式' | sed '表达式'
sed -e 's/old_string/new_string/g' -e 's/another_old_string/another_new_string/g' file.txt
```

等价于
2. 删除文本中的多个行

sed '表达式; 表达式'
```shell
sed -e '1d' -e '/pattern/d' file.txt
```

3. 在文本中插入多个行:

```shell
sed -e '1i\inserted_line1' -e '2i\inserted_line2' file.txt
```

其中,-e 表示指定一个表达式,多个表达式之间用 -e 分隔。每个表达式可以是一个 sed 命令,例如 s、d、i 等。

### 引用

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

0 comments on commit 8b3e8f6

Please sign in to comment.