I would like do the following using awk:
Example of my input data with four columns and a number of rows:
10 20 30 40
50 30 60 80
90 12 40 20
Desired output:
10 20
30 40
>
50 30
60 80
>
90 12
40 20
尝试类似:
awk '{print $1 " " $2 "\n" $3 " " $4 "\n>"}'
输出是:
10 20
30 40
>
50 30
60 80
>
90 12
40 20
>
抱歉拖后腿>
尝试awk '{ print $1" "$2"\n" $3" "$4"\n>" }'
sed -r 's/(\S+\s+){2}/&\n/;$!a >' file
10 20 30 40 > 50 30 60 80 > 90 12 40 20
注意最后一行,没有多余的尾随>
。
我添加了一个纯bash解决方案(不调用任何外部实用程序):
脚本:
while read a b c d; do echo -e "$a $b\n$c $d\n>"; done <infile
或者没有显式循环:
printf "%s %s\n%s %s\n>\n" $(<infile)
输入:
cat >infile <<XXX
10 20 30 40
50 30 60 80
90 12 40 20
XXX
输出:
10 20
30 40
>
50 30
60 80
>
90 12
40 20
>