Is my solution working or not ?
If you don't like the shell piping you can do the paste in the END section either manually or with the system function.
I think this is the same question as another recent post, just re-phrased. Here's my solution....
[tt]
#!/usr/bin/awk -f
{
if ($1 in col) {
cnt=++col[$1];
} else {
col[$1]=1;
row[0]=row[0] " " $1;
cnt=1;
};
row[cnt]=row[cnt] " " $2;
if (cnt>max)
max=cnt;
} END {
for(x=0;x<=max;x++)
print row[x]
}
[/tt]
Tested...
[tt]
a b c
1 2 3
4 5 6
[/tt]
More testing...
[tt]
0 10 20 30 40
99 87 53 64 82
105 92 84 78 89
[/tt]
You can impose your own formatting with sprintf. The first one is used to format the heading, the second for the data ...
[tt]
#!/usr/bin/awk -f
{
if ($1 in col) {
cnt=++col[$1];
} else {
col[$1]=1;
row[0]=row[0] sprintf(" %10.3f",$1);
cnt=1;
};
row[cnt]=row[cnt] sprintf(" %10.3f",$2);
if (cnt>max)
max=cnt;
} END {
for(x=0;x<=max;x++)
print row[x]
}
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.