Chinaunix首页 | 论坛 | 博客
  • 博客访问: 301508
  • 博文数量: 106
  • 博客积分: 1948
  • 博客等级: 上尉
  • 技术积分: 947
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-27 00:11
文章分类

全部博文(106)

文章存档

2014年(1)

2013年(14)

2012年(61)

2011年(30)

分类: LINUX

2012-08-24 15:51:07

sed 'N;/^$/d;G' file.txt   #每两行增加一个空行
G是行尾增加空行
N貌似是2行合成1行




P:Print up to the first embedded newline of the current pattern space.
(就是输出模式空间开头到第一个\n之间的内容)

D:If pattern space contains no newline, start a normal new cycle as if the d command was issued. Otherwise, delete text in the pattern space up to the first newline, and restart cycle with the resultant pattern space, without reading a new line of input.
(是删除模式空间开头到第一个\n(含)之间的内容,并且控制流跳到脚本的第一条语句。这里一定要注意这句话“and restart cycle with the resultant pattern space, without reading a new line of input.”,即它是在不改变当前行号的情况下,从头执行的。)
这句话也充分的说明了,为什么很多人不愿意读中文翻译版书籍的原因。:-)

N:Add a newline to the pattern space, then append the next line of input to the pattern space. If there is no more input then sed exits without processing any more commands.
(追加下一个输入行到模板块后面并在二者间嵌入一个新行,改变当前行号码。如果没有下一个可处理的行,则退出)

阅读(1788) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~