文章目录
sed的介绍
sed是Linux下一款功能强大的非交互流式文本编辑器,可以对文本文件进行增、删、改、查等操作,支持按行、按字段、按正则匹配文本内容,灵活方便,特别适合于大文件的编辑
sed 支持正则表达式,如果要扩展正则需要加 -r参数
sed的执行过程
- 一次读取一行数据
- 根据我们提供的规则来匹配相关的数据,比如查找root。
- 按照命令修改数据流中的数据,比如替换
- 将结果进行输出
- 重复上面四步
sed的用法
调用sed的方法有两种:
- 在命令行指定sed指令对文本进行处理
sed + 选项 “指令” 文件 - 先将sed指令保存到文件中,将该文件作为参数进行调用:
sed +选项 -f 包含sed指令的文件 文件
sed常用选项
options:
参数 | 含义 |
---|---|
-a | 在当前行下面插入文件 |
-n | 读取下一个输 |