如何打印文本文件中的内容,并在每一行后有一个空行?

2 command-line text-processing

这是我输入的内容和得到的输出:

$ cat helloworld.txt

Hello World!
I'm Kanladaporn Sirithatthamrong
6480952
Run Code Online (Sandbox Code Playgroud)

但这就是我想要的输出:

Hello World!

I'm Kanladaporn Sirithatthamrong

6480952
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?请问有什么建议吗?

Jos*_*Jos 10

使用pr

$ pr -Td helloworld.txt
Hello World!

I'm Kanladaporn Sirithatthamrong

6480952

$
Run Code Online (Sandbox Code Playgroud)

man pr

   -d, --double-space
          double space the output

   -T, --omit-pagination
              omit page headers and trailers, eliminate any pagination by form feeds set in input files
Run Code Online (Sandbox Code Playgroud)


Art*_*ild 7

您可以使用sed

sed G helloworld.txt
Run Code Online (Sandbox Code Playgroud)

要仅在还没有空行时添加换行符,请使用:

sed '/^$/d;G' helloworld.txt
Run Code Online (Sandbox Code Playgroud)

参考:SED 的便捷单线