sed 'N' 命令

Posted uxiuxi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sed 'N' 命令相关的知识,希望对你有一定的参考价值。

我的理解是读取第一行并且以new line character \n为分割符 附加到第一行, 之后在处理第二行(最开始的第三行)。 

http://www.thegeekstuff.com/2009/11/unix-sed-tutorial-multi-line-file-operation-with-6-practical-examples/#comments

这篇文章写得特别好。

  • The curly braces “{” and “}” used to group the commands. The curly braces and sed commands must be on the seperate lines.
  • Sed reads the first line and place it in the pattern space, N command reads the next line and appends with the pattern space i.e first line seperated by newline. So now pattern space will have firstline\nsecondline.
  • Next substitution of \n to [email protected] and it prints the pattern space content as its sed default behaviour. So consecutive lines are joined and delimited by ” @ “

以上是关于sed 'N' 命令的主要内容,如果未能解决你的问题,请参考以下文章

sed命令中如何讲一个特殊字符(比如"")替换为换行符?

linux shell sed命令的问题!

sed的基本用法

linux命令怎么显示文件某一行或几行内容

bash shell脚本,如何用sed 命令打印出匹配行和匹配行的第N行

sed打印指定范围