Please help me for calculation between record

HETATM 1302  O   HOH A 201      35.586  -3.107  15.593  0.50  2.00           O  
HETATM 1303  O   HOH A 202      32.775  19.569  17.309  0.61 23.79           O  
HETATM 1304  O   HOH A 203      26.017  14.450  13.420  1.00 28.93           O  
HETATM 1305  O   HOH A 204      21.850   8.006   2.571  0.62 32.64           O  
HETATM 1306  O   HOH A 205      24.749  14.198   2.809  1.00 37.57           O

I want to calculate 6 field ( 201,202,203,204,205 ) between records.

  • No overlap (201 * 201) , No inverse order (202*201)
201 * 202
201 * 203
201 * 204
201 * 205
202 * 203
202 * 204
202 * 205
203 * 204
203 * 205
204 * 205

I tried that

------------------------------------------------------

#!/bin/awk
  
   for (i=1; i<=FNR; i++) {
      if (FNR == i) {
      a = $6
       for (j=i+1; j<=FNR; j++) {
        b = $6
      print a*b
     }
   }
 }

------------------------------------------------

but It doesn't run.

Please help me nice Linux guys
Thank you.

Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

What should your output look like?

Here is something to start with:-

awk '
        {
                A[++c] = $6
        }
        END {
                for ( i = 1; i <= c; i++ )
                        for ( j = i+1; j <= c; j++ )
                                printf "%d * %d = %d\n", A, A[j], (A * A[j])
        }
' file

Will generate below output for your input:-

201 * 202 = 40602
201 * 203 = 40803
201 * 204 = 41004
201 * 205 = 41205
202 * 203 = 41006
202 * 204 = 41208
202 * 205 = 41410
203 * 204 = 41412
203 * 205 = 41615
204 * 205 = 41820