LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 797|回复: 2

新手关于sed的初级问题

[复制链接]
发表于 2007-12-19 20:52:13 | 显示全部楼层 |阅读模式
新手,刚开始学习shell,今天看了zhy版主的sed,很多地方不明白,希望大家帮忙解释一下,万分感谢!
zhy中的一段程序:

(1)
zhyfly@zhyfly:~/bash$ sed -e '=' test.txt
1
The honeysuckle band played all night long for only $90.
2
It was an evening of splendid music and company.
3
Too bad the disco floor fell through at 23:00.
(2)
zhyfly@zhyfly:~/bash$ sed -e '=' test.txt
1
The honeysuckle band played all night long for only $90.
2
It was an evening of splendid music and company.
3
Too bad the disco floor fell through at 23:00.
4
The local nurse Miss P.Neave was in attendance.
(3)
zhyfly@zhyfly:~/bash$ sed -n -e '=' test.txt
1
2
3
4
(4)
zhyfly@zhyfly:~/bash$ sed -n -e '/music/p' test.txt
It was an evening of splendid music and company.
(5)
zhyfly@zhyfly:~/bash$ sed -n -e '/music/=' test.txt
2
zhyfly@zhyfly:~/bash$ sed -n -e '/music/p' -e '/music/=' test.txt
It was an evening of splendid music and company.
2
(6)
zhyfly@zhyfly:~/bash$ sed -e '=;p' test.txt
1
The honeysuckle band played all night long for only $90.
The honeysuckle band played all night long for only $90.
2
It was an evening of splendid music and company.
It was an evening of splendid music and company.
3
Too bad the disco floor fell through at 23:00.
Too bad the disco floor fell through at 23:00.
4
The local nurse Miss P.Neave was in attendance.
The local nurse Miss P.Neave was in attendance.
(7)
zhyfly@zhyfly:~/bash$ sed -n -e '=;p' test.txt
1
The honeysuckle band played all night long for only $90.
2
It was an evening of splendid music and company.
3
Too bad the disco floor fell through at 23:00.
4
The local nurse Miss P.Neave was in attendance.
(8)
zhyfly@zhyfly:~/bash$ sed -n -e '=' -e 'p' test.txt
1
The honeysuckle band played all night long for only $90.
2
It was an evening of splendid music and company.
3
Too bad the disco floor fell through at 23:00.
4
The local nurse Miss P.Neave was in attendance.
zhyfly@zhyfly:~/bash$

前面四个还明白,到了第五个就不明白了,大家给解释下,谢~
 楼主| 发表于 2007-12-19 21:26:31 | 显示全部楼层

第8个明白了,第5,6,7个谁给解释一下阿~~~

第8个,-e选项允许在同一行里执行多条命令,
第8个的意思是给每行加行号码并且输出每行。
其他的三个谁给解释一下阿?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-12-19 22:53:31 | 显示全部楼层

第6,7个明白了,只剩下一个了~~~

呵呵,第6,7个明白了,就剩下第5个有点不懂了。根据zhy老大的理论,
多个命令常用的方法
主要有
a.利用多个-e选项
b.利用 ;
c.使用脚本文件
上面几种方法,前面也有提到。
可以理解第6,7个。
只剩下一个了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表