Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44832
  • 博文数量: 7
  • 博客积分: 153
  • 博客等级: 入伍新兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-22 00:28
文章分类

全部博文(7)

文章存档

2011年(7)

我的朋友

分类: LINUX

2011-11-08 13:44:45



一、说明
  1. 模式空间(pattern space):
  2. 缓冲从文件读取的一行数据,该行数据在pattern space处理后,输出到stdin
  1. 保留空间(hold space):
  2. 缓存通过h、H、x从模式空间缓冲来的数据,默认为空
  1. h:将模式空间复制到保留空间 H:将模式空间追加到保留空降
  2. g:将保留空间复制到模式空间 G:将保留空间追加到模式空间
  3. x:交换模式空间和保留空间的内容
二、应用
 1.在每行后面添加一空行
   
  1. esperantor@ubuntu:~/script$ sed 'G' test
  2. first
  3. second
  4. third
  5. fourth
  6. fifth
  7. esperantor@ubuntu:~/script$
  8. esperantor@ubuntu:~/script$ sed '$!G' test  //对最后一行不起作用
  9. first

  10. second

  11. third

  12. fourth

  13. fifth
  14. esperantor@ubuntu:~/script$ 
 2.在匹配模式前后插入空行
  1. esperantor@ubuntu:~/script$ sed '/third/{x;p;x;}' test  //前面
  2. first
  3. second
  4. third
  5. fourth
  6. fifth
  7. esperantor@ubuntu:~/script$ sed '/third/G' test   //后面
  8. first
  9. second
  10. third
  11. fourth
  12. fifth
  13. esperantor@ubuntu:~/script$ sed '/third/{x;p;x;G;}' test  //前面和后面
  14. first
  15. second
  16. third
  17. fourth
  18. fifth
  19. esperantor@ubuntu:~/script$
































阅读(901) | 评论(0) | 转发(0) |
0

上一篇:vim 配置

下一篇:sed反转文件中的行

给主人留下些什么吧!~~