Convert multiple columns to multiple lines

I have a program which outputs about 100 columns of data. The first 6
are shown:


UTC 10:53:40 power 30 elevation 23

I want to convert that so it outputs

UCT 10:53:40
power 30
elevation 23
...

Any suggestions?
dave [ Fr, 07 Dezember 2007 18:50 ] [ ID #1887705 ]

Re: Convert multiple columns to multiple lines

On Fri, 07 Dec 2007 17:50:19 +0000, Dave wrote:

> I have a program which outputs about 100 columns of data. The first 6
> are shown:
>
>
> UTC 10:53:40 power 30 elevation 23
>
> I want to convert that so it outputs
>
> UCT 10:53:40
> power 30
> elevation 23
> ..
>
> Any suggestions?

Well, if you want to split them pairwise, you could use

awk '{for(i=1;i<NF;i+=2) print $i,$(i+1); }'

If you need more, e.g. you have an odd number of columns, or pairwise is
not exactly what you want then you will need to give us more information.
Icarus Sparry [ Fr, 07 Dezember 2007 19:07 ] [ ID #1887706 ]

Re: Convert multiple columns to multiple lines

"Dave" wrote ...
>I have a program which outputs about 100 columns of data. The first 6 are
>shown:
>
>
> UTC 10:53:40 power 30 elevation 23
>
> I want to convert that so it outputs
>
> UCT 10:53:40
> power 30
> elevation 23
> ..

With GNU Awk:

awk 'ORS=NR%2?FS:"\n"' RS="[ \n]" filename


Dimitre
cichomitiko [ Fr, 07 Dezember 2007 19:35 ] [ ID #1887710 ]

Re: Convert multiple columns to multiple lines

Dave wrote:
> I have a program which outputs about 100 columns of data. The first 6
> are shown:
>
>
> UTC 10:53:40 power 30 elevation 23
>
> I want to convert that so it outputs
>
> UCT 10:53:40
> power 30
> elevation 23
> ..
>
> Any suggestions?


printf "%s %s\n" $( program_that_outputs_data )


Janis
Janis Papanagnou [ Fr, 07 Dezember 2007 20:38 ] [ ID #1887713 ]
Linux » comp.unix.shell » Convert multiple columns to multiple lines

Vorheriges Thema: How to remove -.o
Nächstes Thema: insert "comment" characters in a file