| Author |
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?
| |
| Icarus Sparry 2007-12-07, 1:29 pm |
| 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.
| |
| Radoulov, Dimitre 2007-12-07, 1:29 pm |
|
"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
| |
| Janis Papanagnou 2007-12-07, 7:23 pm |
| 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
| |
|
| Icarus Sparry wrote:
> On Fri, 07 Dec 2007 17:50:19 +0000, Dave wrote:
>
>
> 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.
Thank you. That worked fine.
| |
| Cyrus Kriticos 2007-12-08, 7:42 pm |
| 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
> ..
name_of_your_program | xargs -n 2 echo
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
| |
| Cyrus Kriticos 2007-12-08, 7:42 pm |
| Cyrus Kriticos wrote:
> Dave wrote:
>
> name_of_your_program | xargs -n 2 echo
or
name_of_your_program | xargs -n 2
--
Best regards | Be nice to America or they'll bring democracy to
Cyrus | your country.
|
|
|
|