transform rows into columns in bash
Hi,
I would like to transform rows into columns from a file in bash. This is the file Code:
param1 value1 Code:
param1 param2 param3 |
Quote:
Something like this? Code:
{ Cheers, Tink |
The problem with bash is that it does not support multi-dimensional arrays - so you have to use awk, perl, pthyon, ruby or suchlike to transpose the contents of your file.
Here is one way of doing what you want to do using Python and zip* Code:
!/usr/bin/python Code:
"param1" "value1" Code:
"param1" "param2" "param3" |
Code:
for i in 1 2 ; do cat input | cut -d' ' -f$i | paste -s >> output ; done |
Well as with the others my solution only works for the 2 column scenario as well:
Code:
awk '{print $1;s[NR]=$2}END{printf "\n";for(i in s)print s[i]}' ORS=" " file |
All times are GMT -5. The time now is 11:25 AM. |