sed编辑器基础
来源:互联网 发布:网络教育专科报名 编辑:程序博客网 时间:2024/06/06 03:05
一、 更多的替换选项
①替换标记
替换格式: s/pattern/replacement/flags
4种可用的替换标记:
数字:表明新闻本将替换第几处模式匹配的地方;
g,表明新文本将会替换所有匹配的文本;
p,表明原先行的内容要打印出来;
w file,将替换的结果写到文件中。
可以指定sed编辑器用新文本替换第几处模式匹配的地方。
后面第二个test被替换掉了。
用g替换标记,能替换全部
p替换标记会只打印修改过的行,和-n选项(禁止输出)一起使用。
②替换字符
替换(/),可以用其他字符替换字符串分隔符
二、使用地址
sed有两种形式的行寻址:
①以数字形式表示行区间
②用文本模式来过滤出行
[address] command
1.数字方式的行寻址
①替换标记
- root@localhost sed]# cat data4.txt
- This is a test of the test script.
- This is the second test of the test script.
- [root@localhost sed]# sed 's/test/trial/' data4.txt
- This is a trial of the test script.
- This is the second trial of the test script.
替换格式: s/pattern/replacement/flags
4种可用的替换标记:
数字:表明新闻本将替换第几处模式匹配的地方;
g,表明新文本将会替换所有匹配的文本;
p,表明原先行的内容要打印出来;
w file,将替换的结果写到文件中。
可以指定sed编辑器用新文本替换第几处模式匹配的地方。
- [root@localhost sed]# sed 's/test/trial/2' data4.txt
- This is a test of the trial script.
- This is the second test of the trial script.
用g替换标记,能替换全部
- [root@localhost sed]# sed 's/test/trial/g' data4.txt
- This is a trial of the trial script.
- This is the second trial of the trial script.
p替换标记会只打印修改过的行,和-n选项(禁止输出)一起使用。
- [root@localhost sed]# cat data5.txt
- This is a test line.
- This is a different line.
- [root@localhost sed]# sed -n 's/test/trial/p' data5.txt
- This is a trial line.
②替换字符
替换(/),可以用其他字符替换字符串分隔符
- [root@localhost sed]# sed -n 's!/bin/bash!/bin/csh!p' /etc/passwd
- root:x:0:0:root:/root:/bin/csh
- tq2440:x:500:500:tq2440:/home/tq2440:/bin/csh
- win:x:501:501::/home/win:/bin/csh
二、使用地址
sed有两种形式的行寻址:
①以数字形式表示行区间
②用文本模式来过滤出行
[address] command
1.数字方式的行寻址
- [root@localhost sed]# sed '2s/dog/cat/' data1.txt
- The quick brown fox jumps over the lazy dog.
- The quick brown fox jumps over the lazy cat.
- The quick brown fox jumps over the lazy dog.
0
上一篇:初识sed和gwak
下一篇:nucleus plus代码学习
相关热门文章
- linux 常见服务端口
- xmanager 2.0 for linux配置
- 【ROOTFS搭建】busybox的httpd...
- openwrt中luci学习笔记
- Linux里如何查找文件内容...
给主人留下些什么吧!~~
评论热议
阅读全文
0 0
- sed编辑器基础
- Linux学习笔记-sed编辑器基础
- sed编辑器基础之替换命令
- Linux基础之sed流编辑器详解
- sed编辑器
- sed编辑器
- sed编辑器
- sed编辑器基础之替换命令(二)
- sed基础
- sed基础
- sed基础
- sed编辑器学习笔记
- 使用 sed 编辑器
- 使用 sed 编辑器
- 使用 sed 编辑器
- 使用 sed 编辑器[转]
- 使用 sed 编辑器
- 使用 sed 编辑器
- USB驱动程序设计
- IDEA Tomcat Debug启动非常慢
- 初识sed和gwak
- 信号和槽函数的基础实现
- 最常用的1000个Java类(附代码示例)
- sed编辑器基础
- nucleus plus代码学习
- nucleus学习
- nucleus plus学习总结
- nucleus 学习 中断
- 解决html表格字体
- nucleus plus学习总结(后续)
- 光衰代码整理学习
- 5-32 哥尼斯堡的“七桥问题”(并查集+度的判断)
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
养龟用什么缸
不锈钢养龟箱
养龟用什么水
家庭如何养龟
养龟要放多少水
养龟有什么讲究
养什么龟好
家里养什么龟好
乌龟养殖技术
养殖龟
黄缘闭壳龟养殖技术
鳄龟养殖
黄缘闭壳龟养殖
鳄鱼龟养殖
黄缘闭壳龟的养殖
鳄鱼龟怎么养
黄缘闭壳龟的养殖技术
黄缘闭壳龟的饲养
家养乌龟怎么养
鳄鱼龟养殖技术
龟养殖
养乌龟的方法
旱龟怎么养
黄缘闭壳龟饲养环境
哪个生肖不宜养龟
那个生肖不宜养龟
什么生肖适合养龟
什么属相不适合养龟
无过滤三年不换水养龟
什么样的人不适合养龟
兼
兼爱
兼祧
兼毫
兼辆
兼葭
日兼
兼词
兼松
得兼
兼济