What I tried is to cut each block (by field 1) to separate file and then use "paste" to combine the individual files. I feel there must be an easier way with awk.
Any help will be appreciated.
Thanks Jotne!
Two reasons for this output.
1) I need this output for other statistics like min, max, mean, 5number etc of each block to compare the other 96 blocks in the output format;
2) There are many posts about "line-to-column" script in awk to do the similar conversion, I thought my case may be resolved with awk too, but could not figure out by myself.
I am aware of the line numbers are now equal for each block, so that it is more challenging to me.
Does this make any sense? Please give me any suggestion or comments. Thanks a lot!
awk '
NR == FNR {
if (!($1 in C))
{
C[$1]
V[++k] = $1
}
next
}
p != $1 {
c = 0
}
{
A[$1","++c] = $0
p = $1
if ( m < c )
m = c
}
END {
for ( i = 1; i <= m; i++ )
{
for ( j = 1; j <= k; j++ )
{
printf "%s\t", A[V[j]","i] ? A[V[j]","i] : "\t\t"
}
printf "\n"
}
}
' file file
Thanks MIG and Yoda!
MIG, your code is what I was looking for.
How about if I have same header for each block as "ID Length Per"?
ID Length Per
1 7043 3.864
2 54477 29.89
3 104841 57.52
ID Length Per
1 1150 0.835
2 1321 0.96
3 6432 4.675
4 6922 5.031
5 11705 8.507
6 13793 10.02
7 34275 24.91
8 38238 27.79
ID Length Per
1 11398 8.887
2 17396 13.56
3 94014 73.3
which is the original data structure. I first struggled with RS, but could not figure out the way. Then I added the first field as the group ID.
Is it possible to use the RS to handle the original situation? Thanks!
Thanks Shamrock!
This is really complicated, and I probably need use MadeIGermany's answer which make the parsing easier for me. Again, thank you guys for all your input.
to concatenate the output to a file! Amazing trick!
Only when I saw your code did I realized your trick to make use of the functions of awk. Can you recommend any good reference book(s) about awk, besides the GNU manual,and the classic SED &AWK? Thanks a lot!