![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| just want certail elements | frenchface | Shell Programming and Scripting | 1 | 05-10-2008 06:38 PM |
| How do I transpose a column of results to a row | m223464 | Shell Programming and Scripting | 6 | 05-06-2008 04:33 AM |
| Map - printing all elements - why? | dhanamurthy | High Level Programming | 0 | 04-14-2008 10:19 AM |
| Row to column transpose | videsh77 | Shell Programming and Scripting | 10 | 06-16-2007 09:54 AM |
| transpose command | su_in99 | UNIX for Dummies Questions & Answers | 3 | 05-16-2007 02:10 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
How to transpose data elements in awk
Hi,
I have an input data file :- Test4599,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,2,2,R ain Test90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,N ot Rain etc.... I wanted to transpose these data to:- Test4599 Test90 0 0 0 0 .. ... In other words, I wanted to transpose elements from vertical to horizontal. Any idea on how to do that using Awk? Please advise. Thanks. |
| Forum Sponsor | ||
|
|
|
|||
|
awk -F, 'BEGIN {max_i=0} { \
for(i=1;i<=NF;i++) {text_arr[NR SUBSEP i]=$NF} \ if ( NF > max_i ) {max_i = NF}} \ END { for(i=1;i<=max_i;i++) { for(j=1;j<=NR;j++)\ printf text_arr[j SUBSEP i];print}}}' file.txt I did not tested it, but should be very close to the final solution. Luck |
|||
| Google The UNIX and Linux Forums |