在使用bash / linux的特定行之后创build一个空行

我需要在使用sed的第45行之后添加一个额外的空白行

例如:

44 some text one 45 some text two 46 some text three 47 some text four 

结果:

 44 some text one 45 some text two 46 47 some text three 48 some text four 

我试过使用

 sed '45G' myfile.txt 

但似乎没有工作,它确实在屏幕上打印文件的内容,但不会在第45行之后添加任何空格

使用CentOS 7最小化

你可以做:

 sed $'45 a \n' file.txt 
  • $''启动C风格的引用,在使用\n时可能需要在某些sed

  • 45a \n在( a )第45行之后附加一个换行符( \n

sed是为了简单替换个别行,就是这样。 对于其他任何东西只要使用awk:

 awk '{print} NR==45{print ""}' file 

这将适用于任何UNIX框上的awk。