稿定设计导出-20190315-02246.png
- ref
- 格式
sed [options] 'command' file(s)
sed -f scriptfile file(s)
options: -e; -n
command: 行定位(正则) + sed命令(操作)
cmd | desc | usage |
---|---|---|
p | 打印 | sed -n '1,2p' |
s | 取代 | sed 's/false/true/' file |
a | 新增 | |
i | 插入 | |
c | 取代 | |
d | 删除 | |
1~2 | 起始~步长 | |
高级 |
- | - |
{;;} |
复合命令 | {n;p;n} |
& | 全反向引用 | sed 's/^[a-z_-]/& /' passwd |
s/\(..\)xx\(..\)/\1yy\2 |
分组与部分反向引用 | |
\u\l \U\L |
(首字母) 大小写 |
sed 's/^[a-z_-]\+/\u&/' passwd |
q | 退出sed | |
读写 |
- | - |
r | 定位file第一行,读取123 | sed '1r 123.txt' abc.txt |
w | 定位file第一行,写入abc(全覆盖)` | sed '1w abc.txt' 123.txt |
| | 多个sed管道操作 | sed -n '/inet /p'|sed 's/ine.*r:\([0-9.]\+\).*$/\1/' |