码迷,mamicode.com
首页 > 其他好文 > 详细

sed系列:多命令执行

时间:2015-01-14 15:35:56      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

Syntax: 
#sed -e ‘command‘ -e ‘command‘ filename 
Note: -e option is optional for sed with single command. sed will execute the each set of command while processing input from the pattern buffer. 
让我们先创建示例文件 
# cat thegeekstuff.txt 
1. Linux - Sysadmin, Scripting etc. 
2. Databases - Oracle, mySQL etc. 
3. Hardware 
4. Security (Firewall, Network, Online Security etc) 
5. Storage 
6. Cool gadgets and websites 
7. Productivity (Too many technologies to explore, not much time available) 
8. Website Design 
9. Software Development 

10.Windows- Sysadmin, reboot etc

例1:删除第1行和第4行 
$sed -e ‘4d‘ -e ‘2d‘ thegeekstuff.txt 

1. Linux - Sysadmin, Scripting etc. 
3. Hardware 
5. Storage 
6. Cool gadgets and websites 
7. Productivity (Too many technologies to explore, not much time available) 
8. Website Design 
9. Software Development 

10.Windows- Sysadmin, reboot etc. 


例2:输出模式匹配1和模式匹配行2 
$sed -n -e ‘/Storage/p‘ -e /Software/p thegeekstuff.txt 

5. Storage 
9. Software Development 


例3:删除第一行,最后一行和空行 
$sed -e ‘1d‘ -e ‘$d‘ ‘/^$/d‘ thegeekstuff.txt 

sed: can‘t read /^$/d: No such file or directory 
2. Databases - Oracle, mySQL etc. 
3. Hardware 
4. Security (Firewall, Network, Online Security etc) 
5. Storage 
6. Cool gadgets and websites 
7. Productivity (Too many technologies to explore, not much time available) 
8. Website Design 
9. Software Development 
$sed ‘ 
> 1d 
> $d 
> /^$/d 
> ‘ thegeekstuff.txt 
2. Databases - Oracle, mySQL etc. 
3. Hardware 
4. Security (Firewall, Network, Online Security etc) 
5. Storage 
6. Cool gadgets and websites 
7. Productivity (Too many technologies to explore, not much time available) 
8. Website Design 
9. Software Development 
$

sed系列:多命令执行

标签:

原文地址:http://blog.csdn.net/iloveyin/article/details/42710181

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!