如何向任何输出添加“双行间距”?

Pet*_*ver 2 bash

我想获取 bash 命令的输出(在本例中为 grep)并每隔一行插入一个空行:

not
like
this ...

but

like

this!
Run Code Online (Sandbox Code Playgroud)

在 bash 中做到这一点的聪明方法?

fpm*_*phy 6

有很多方法可以对文本文件执行此操作。最简单的大概是

$ sed G filename
Run Code Online (Sandbox Code Playgroud)


ste*_*ver 5

使用prcoreutils

$ grep '' file | pr -Td
not

like

this ...
Run Code Online (Sandbox Code Playgroud)

(请注意,这在最后一行加倍空格 - 不像,比如说,sed '$!G')。来自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)