2

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
4

4 回答 4

2

尝试类似:

awk '{print $1 " "  $2 "\n" $3 " " $4 "\n>"}'

输出是:

10 20
30 40
>
50 30
60 80
>
90 12
40 20
>

抱歉拖后腿>

于 2013-06-13T09:58:07.053 回答
1

尝试awk '{ print $1" "$2"\n" $3" "$4"\n>" }'

于 2013-06-13T10:01:09.657 回答
1

GNU

sed -r 's/(\S+\s+){2}/&\n/;$!a >' file
10 20
30 40
>
50 30
60 80
>
90 12
40 20

注意最后一行,没有多余的尾随>

于 2013-06-13T12:00:19.953 回答
0

我添加了一个纯解决方案(不调用任何外部实用程序):

脚本:

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
>
于 2013-06-13T11:47:07.393 回答