如何使用AWK或Sed在x个单词之后插入换行符\n

use*_*669 3 unix linux bash shell awk

我在一行中有这个:

We were born in the earth beyond the land
Run Code Online (Sandbox Code Playgroud)

我希望它在3个单词行中,如下所示:

We were born
in the earth 
beyond the land
Run Code Online (Sandbox Code Playgroud)

Chr*_*our 9

$ xargs -n3 < file
We were born
in the earth
beyond the land

$ egrep -o '\S+\s+\S+\s+\S+' file 
We were born
in the earth
beyond the land
Run Code Online (Sandbox Code Playgroud)

  • 嗯,xargs看起来很明显_now_ :-) (2认同)