| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2666 人关注过本帖
标题:Sed编辑器
只看楼主 加入收藏
guixiaolan
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:356
专家分:0
注 册:2006-4-20
收藏
 问题点数:0 回复次数:2 
Sed编辑器
[gxlinux@localhost ~]$ cat sed
1.line one.
2.the second line.
3.the third.
4.this is line four.
5.five
6.this is the sixth sentence.
7.this is line seven.
8.eight and last.
[gxlinux@localhost ~]$ sed '/last/ p' sed #正则表达式
1.line one.
2.the second line.
3.the third.
4.this is line four.
5.five
6.this is the sixth sentence.
7.this is line seven.
8.eight and last.
8.eight and last.
[gxlinux@localhost ~]$ sed '/last/ p' sed -n
8.eight and last.
[gxlinux@localhost ~]$ sed '3,6 p' sed -n
3.the third.
4.this is line four.
5.five
6.this is the sixth sentence.
[gxlinux@localhost ~]$ sed '3,6 !p' sed -n
1.line one.
2.the second line.
7.this is line seven.
8.eight and last.
[gxlinux@localhost ~]$ sed '$ p' sed -n
8.eight and last.
[gxlinux@localhost ~]$ sed '3 q' sed
1.line one.
2.the second line.
3.the third.
[gxlinux@localhost ~]$ cat>print3
3,6 p
[gxlinux@localhost ~]$ sed -n -f print3 sed
3.the third.
4.this is line four.
5.five
6.this is the sixth sentence.
[gxlinux@localhost ~]$ cat zhiling
/one/ i\
first
/second/ a\
two
3,4 c\
gxl
linux
s/last/fedora/
[gxlinux@localhost ~]$ sed -f zhiling sed
first
1.line one.
2.the second line.
two
gxl
linux
5.five
6.this is the sixth sentence.
7.this is line seven.
8.eight and fedora.
[gxlinux@localhost ~]$ sed 's/last/fedora/p' -n sed
8.eight and fedora.
[gxlinux@localhost ~]$ sed 's/last/fedora/w temp' sed
1.line one.
2.the second line.
3.the third.
4.this is line four.
5.five
6.this is the sixth sentence.
7.this is line seven.
8.eight and fedora.
[gxlinux@localhost ~]$ cat temp
8.eight and fedora.

[gxlinux@localhost ~]$ cat>zhiling
2,$g #从第二行开始处理,将一个换行符和hold区中的内容追加到pattern区中之后(h与g相反,x交换pattern区与hold区内容)
h
$!d #不是最后一行 删除
#所有命令都是工作在pattern区,并且是一行一行的处理,读取一行到pattern区然后将pattern区中的内容显示出来
#读取第一行到pattern区,将pattern区中的内容复制到hold区,删除pattern区内容(hold区中为第一行)
#读取第二行到pattern区,将一个换行符和hold区中的内容追加pattern区中,然后将其存储到hold区中,删除pattern区内容(hold区中为第二行加第一行)
#读取第八行到pattern区,将一个换行符和hold区中的内容追加pattern区中,然后将其存储到hold区中(此时pattern区内容就是倒过来的了,然后输出)
[gxlinux@localhost ~]$ sed -f zhiling sed
8.eight and last.
7.this is line seven.
6.this is the sixth sentence.
5.five
4.this is line four.
3.the third.
2.the second line.
1.line one.

[gxlinux@localhost ~]$ cat>zhiling
h #将pattern区中的内容复制到hold区中,hold区中原有内容丢失
n #跳过,读取下一行
p
g #与h指令相反
p
#首先读入一行并将它存入到hold区,然后读入下一行并显示,再获取先前的行并显示它,接着处理后续两行
[gxlinux@localhost ~]$ sed -nf zhiling sed
2.the second line.
1.line one.
4.this is line four.
3.the third.
6.this is the sixth sentence.
5.five
8.eight and last.
7.this is line seven.
搜索更多相关主题的帖子: Sed sed 编辑器 line last 
2008-04-14 17:24
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
这么少点代码就实现了??
2008-04-15 15:09
guixiaolan
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:356
专家分:0
注 册:2006-4-20
收藏
得分:0 
回复 1# 的帖子
将上面的东西添加了一些注释,那样会好懂一点.里面是一个word

sed编辑器.rar (5.3 KB)

[url=http://www./]/sign/free.gif" target="_blank">http://ip./sign/free.gif[/url]
2008-04-20 11:42
快速回复:Sed编辑器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018123 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved