![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to transpose data elements in awk | ahjiefreak | Shell Programming and Scripting | 2 | 05-13-2008 05:44 AM |
| How do I transpose a column of results to a row | m223464 | Shell Programming and Scripting | 6 | 05-06-2008 08:33 AM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| transpose command | su_in99 | UNIX for Dummies Questions & Answers | 3 | 05-16-2007 06:10 AM |
| Replace 10th column with a new column--- Terriblly hurry | ahmedwaseem2000 | Shell Programming and Scripting | 2 | 09-06-2005 02:10 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
This has been discussed very recently, and an Awk solution was presented. Here's a Ruby one: Code:
ruby -F, -lane '
BEGIN{$a=[]};$a.concat([$F]);END{$a.transpose.each{|x|puts x.join(",")}}
' infile
1,2,3,4 5,6,7,8 becomes 1,5 2,6 3,7 4,8 |
|
||||
|
see if it works
Put this is a file - testawk.awk Code:
BEGIN {FS=","}
{
for (i=1;i<=NF;i++)
{
arr[NR,i]=$i;
if(big <= NF)
big=NF;
}
}
END {
for(i=1;i<=big;i++)
{
for(j=1;j<=NR;j++)
{
printf("%s\t",arr[j,i]);
}
printf("\n");
}
}
awk -f testawk.awk testfile |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|