我试图用awk将一行切成多行。每两个字之后。使用awk将行切成多行
输入:
hey there this is a test
输出:
hey there
this is
a test
我能够用xargs的去实现它,如下:
echo hey there this is a test |xargs -n2
hey there
this is
a test
但是我很好奇,想知道如何才达到这使用awk。这是我正在使用的命令,这当然没有给出预期的结果。
echo hey there this is a test | awk '{ for(i=1;i<=NF;i++) if(i%2=="0") ORS="\n" ;else ORS=" "}1'
hey there this is a test
而且
echo hey there this is a test | awk '{$1=$1; for(i=1;i<=NF;i++) if(i%2==0) ORS="\n" ;else ORS=" "}{ print $0}'
hey there this is a test
需要知道什么是上面awk命令以及如何进行修改,以提供正确的输出概念是错误的。假设输入是单行的。
感谢和问候。
++很好,它的工作。明白我在做什么失误。谢谢。 –