Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all, I have a such input file : <N+1> <x0> <x1> <x2> ... <xN> <y0> <z0,0> <z1,0> <z2,0> ... <zN,0> <y1> <z0,1> <z1,1> <z2,1> ... <zN,1> <y2> <z0,2> <z1,2> <z2,2> ... <zN,2> and I would like to get an output file as following: <x0> <y0> <z0,0> <x0> <y1> <z0,1> <x0> <y2> <z0,2> : : : <x1> <y0> <z1,0> <x1> <y1> <z1,1> <x1> <y2> <z1,2> : : : <x2> <y0> <z2,0> <x2> <y1> <z2,1> <x2> <y2> <z2,2> : : : Thank you in advance for answering. Best regards, Stefanie
Post Follow-up to this messageOn Mon, 20 Aug 2007 21:15:58 +0200, Steffi wrote:
> Hi all,
>
> I have a such input file :
>
> <N+1> <x0> <x1> <x2> ... <xN>
> <y0> <z0,0> <z1,0> <z2,0> ... <zN,0>
> <y1> <z0,1> <z1,1> <z2,1> ... <zN,1>
> <y2> <z0,2> <z1,2> <z2,2> ... <zN,2>
>
> and I would like to get an output file as following:
>
> <x0> <y0> <z0,0>
> <x0> <y1> <z0,1>
> <x0> <y2> <z0,2>
> : : :
> <x1> <y0> <z1,0>
> <x1> <y1> <z1,1>
> <x1> <y2> <z1,2>
> : : :
> <x2> <y0> <z2,0>
> <x2> <y1> <z2,1>
> <x2> <y2> <z2,2>
> : : :
>
> Thank you in advance for answering.
>
> Best regards,
> Stefanie
Hi Steffi, hello netlanders,
a straightforward script, which solves your problem:
NR == 1 {
N = $1 -1
for (i = 2; i <= N; ++i)
x[i-2] = $i
}
NR >= 2 {
y[NR-2] = $1
for (i = 2; i <= N; ++i)
z[i-2, NR-2] = $i
}
END {
for (sect = 0; sect <= NR - 2; ++sect) {
for (i = 0; i <= NR - 2; ++i)
printf "%s\t%s\t%s\n", x[sect], y[i], z[sect,i]
print ":::"
}
}
Enjoy it,
Steffen Schuler
Post Follow-up to this messageOn Mon, 20 Aug 2007 21:11:18 +0000, Steffen Schuler wrote:
> On Mon, 20 Aug 2007 21:15:58 +0200, Steffi wrote:
>
>
> Hi Steffi, hello netlanders,
>
> a straightforward script, which solves your problem:
>
> NR == 1 {
> N = $1 -1
> for (i = 2; i <= N; ++i)
> x[i-2] = $i
> }
> NR >= 2 {
> y[NR-2] = $1
> for (i = 2; i <= N; ++i)
> z[i-2, NR-2] = $i
> }
> END {
> for (sect = 0; sect <= NR - 2; ++sect) {
> for (i = 0; i <= NR - 2; ++i)
> printf "%s\t%s\t%s\n", x[sect], y[i], z[sect,i]
> print ":::"
> }
> }
Corrected script:
NR == 1 {
N = $1 -1
for (i = 2; i <= NF; ++i)
x[i-2] = $i
}
NR >= 2 {
y[NR-2] = $1
for (i = 2; i <= NF; ++i)
z[i-2, NR-2] = $i
}
END {
for (sect = 0; sect <= N; ++sect) {
for (i = 0; i <= NR - 2; ++i)
printf "%s\t%s\t%s\n", x[sect], y[i], z[sect,i]
print ":::"
}
}
Sorry,
Steffen Schuler
Post Follow-up to this messageSteffi wrote:
> Hi all,
>
> I have a such input file :
>
> <N+1> <x0> <x1> <x2> ... <xN>
> <y0> <z0,0> <z1,0> <z2,0> ... <zN,0>
> <y1> <z0,1> <z1,1> <z2,1> ... <zN,1>
> <y2> <z0,2> <z1,2> <z2,2> ... <zN,2>
>
> and I would like to get an output file as following:
>
> <x0> <y0> <z0,0>
> <x0> <y1> <z0,1>
> <x0> <y2> <z0,2>
> : : :
> <x1> <y0> <z1,0>
> <x1> <y1> <z1,1>
> <x1> <y2> <z1,2>
> : : :
> <x2> <y0> <z2,0>
> <x2> <y1> <z2,1>
> <x2> <y2> <z2,2>
> : : :
>
> Thank you in advance for answering.
>
> Best regards,
> Stefanie
NR==1 { for (i=2;i<=NF;i++) X[i]=$i; next }
{ Y[NR]=$1; for (i=2;i<=NF;i++) Z[i,NR]=$i }
END { for (x=2;x<=NF;x++)
for (y=2;y<=NR;y++)
print X[x],Y[y],Z[x,y]
}
Regards,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.