Link to home
Start Free TrialLog in
Avatar of tomatocans
tomatocans

asked on

Loop for awk



             In the following awk script

             BEGIN{
                     FS="|"
             }
             {
               if($1=="NAME"){
             VOLUME_NAME=$2
               }
               if($1=="LOCATION"){
                  LOCATION_LAT[i]=$2
                  LOCATION_LNG[i]=$3
                          LAT_DEG[i]=substr($2,1,2)
                          LAT_MIN[i]=substr($2,3,2)
                          LAT_SEC[i]=substr($2,5,2)
                          LNG_DEG[i]=substr($3,1,3)
                          LNG_MIN[i]=substr($3,4,2)
                          LNG_SEC[i]=substr($3,6,2)
                          LAT[i]=LAT_DEG[i] + LAT_MIN[i] / 60. + LAT_SEC[i] / 3600.
                          LNG[i]=LNG_DEG[i] + LNG_MIN[i] / 60. + LNG_SEC[i] / 3600.
                          ?????????????
                       }
                       if($1="DATA"){
                          ALT_LOW=$2
                          ALT_HIGH=$3
                       }
                       for(i=1;i<=???????????;i++){
                          print
             (VOLUME_NAME"|"LOCATION_LAT[i]","LOCATION_LNG[i]"|"LAT[i]"|"LNG[i]"|"ALT_LOW"|"ALT_HIGH)

             }
             }

             What is needed to make this for loop print correctly. I think I have to assign a number based on
             LOCATION_LAT[i] but I can't seem to get it right.

             Thanks
Avatar of monas
monas
Flag of Lithuania image

If you know that data is the last, then you could print the line _WHEN_ you find that $1="DATA"
YOu won't need a loop.
ASKER CERTIFIED SOLUTION
Avatar of prakashk021799
prakashk021799

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tomatocans
tomatocans

ASKER

Thanks. The perfect solution.