hey,
i have the following data:
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
4.600000
9.800000
12.70000
12.90000
33.80000
The following command , awk '{a[NR%14+1]=a[NR%14+1]" "$0} END {for (i in a){print a[i]}}', yields:
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 4.600000
0.000000 0.000000 9.800000
0.000000 0.000000 12.70000
0.000000 0.000000 33.80000
0.000000 0.000000 12.90000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
where i want the last column to be
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
4.600000
9.800000
12.70000
12.90000
33.80000. The ascending order is lost...
Can anyone help?
Thanx:)
nawk '
{idx=FNR%14+1}
!(idx in a){key[++key[0]]=idx}
{a[idx]=a[idx] OFS $0}
END {for(i=1;i<=key[0];i++) print a[key]}' myFile
nice, that worked perfectly...
Thanx alot
you probably need to this tweak if to be a bit more pedantic:
nawk '
{idx=FNR%14+1}
!(idx in a){key[++key[0]]=idx}
{a[idx]=(idx in a) ? a[idx] OFS $0 : $0}
END {for(i=1;i<=key[0];i++) print a[key]}' myFile
cool, I'll use it and see what it does differently under different situations...
not quite sure what you did, but it works... hehe.
Can make out some of the code, but need to check out the rest unless you can explain it better to me...
Thanx alot
vgersh99:
you probably need to this tweak if to be a bit more pedantic:
nawk '
# build the index (idx) for the associative array
{idx=FNR%14+1}
# if index (idx) is NOT in array (a), create annay "key"
# the index to "key" is the incremented counter stored in key[0]
# at the end of the processing, key[0] will contain the number of
# UNIQUE indecies (idx)/
!(idx in a){key[++key[0]]=idx}
# if "idx" in already in "a", add "$0" to it; if "idx" is NOT in a assign $0
# to it - this prevents a[idx] have a leading field separator/OFS
{a[idx]=(idx in a) ? a[idx] OFS $0 : $0}
# iterate through array "a" indexed by the values stored in array "key"
# indexed from 1 to max stored in "key[0]"
END {for(i=1;i<=key[0];i++) print a[key]}' myFile
The above assumes that the input 'stream' has already been sorted in the desired output order.
nawk -v col="$1" '{_[NR]=$0;lines=NR}
END{
tmp=lines/col
for(i=1;i<=tmp;i++)
{
for(j=1;j<=col;j++)
printf("%s ",_[i+(j-1)*col])
print ""
}
}' yourfile