linux - Gawk not working correctly in finding min between 3 lines -


i have following gawk script:

begin{     count = 0     imp = ""     time = 0 }  {      if(count==0){         imp = $0         time = $7         count = 1     }      else if(count==1 || count==2){          if($7 < time){             imp = $0             time = $7         }              count+=1      }      else{         count=0         print imp     }  } 

and bunch of files this:

1 57 0.850000 0.000010 0.784696 0.114561 0.670135 1 57 0.850000 0.000010 0.783619 0.114349 0.669270 1 57 0.850000 0.000010 0.725526 0.114805 0.610721 2 57 0.850000 0.000010 1.590584 0.102643 1.487942 2 57 0.850000 0.000010 1.291972 0.076006 1.215967 2 57 0.850000 0.000010 1.224136 0.063005 1.161131 4 57 0.850000 0.000010 0.679327 0.062899 0.616428 4 57 0.850000 0.000010 0.680867 0.062456 0.618411 4 57 0.850000 0.000010 0.684800 0.063411 0.621389 8 57 0.850000 0.000010 0.374985 0.063619 0.311367 8 57 0.850000 0.000010 0.401494 0.062838 0.338655 8 57 0.850000 0.000010 0.405216 0.064353 0.340862 12 57 0.850000 0.000010 0.317534 0.063243 0.254290 12 57 0.850000 0.000010 0.317531 0.063118 0.254413 12 57 0.850000 0.000010 0.318544 0.063321 0.255222 16 57 0.850000 0.000010 0.379314 0.063865 0.315448 16 57 0.850000 0.000010 0.382251 0.064108 0.318144 16 57 0.850000 0.000010 0.381444 0.063148 0.318296 20 57 0.850000 0.000010 0.333159 0.063614 0.269545 20 57 0.850000 0.000010 0.336454 0.063309 0.273144 20 57 0.850000 0.000010 0.333363 0.063646 0.269717 24 57 0.850000 0.000010 0.589092 0.066359 0.522733 24 57 0.850000 0.000010 0.429424 0.066578 0.362845 24 57 0.850000 0.000010 0.335697 0.068287 0.267411 1 100 0.850000 0.000000 0.793457 0.060388 0.733069 1 100 0.850000 0.000000 0.791233 0.060041 0.731192 1 100 0.850000 0.000000 0.789624 0.060151 0.729474 2 100 0.850000 0.000000 2.140322 0.063280 2.077041 2 100 0.850000 0.000000 2.104924 0.063320 2.041604 2 100 0.850000 0.000000 2.110660 0.063040 2.047621 4 100 0.850000 0.000000 1.145730 0.063037 1.082693 4 100 0.850000 0.000000 1.139739 0.062964 1.076775 4 100 0.850000 0.000000 1.141787 0.063186 1.078601 8 100 0.850000 0.000000 0.656741 0.063040 0.593701 8 100 0.850000 0.000000 0.660081 0.063351 0.596730 8 100 0.850000 0.000000 0.659872 0.063350 0.596522 12 100 0.850000 0.000000 0.511580 0.063247 0.448333 12 100 0.850000 0.000000 0.509540 0.063253 0.446287 12 100 0.850000 0.000000 0.503905 0.062864 0.441041 16 100 0.850000 0.000000 0.613314 0.063025 0.550289 16 100 0.850000 0.000000 0.619024 0.063526 0.555498 16 100 0.850000 0.000000 0.622365 0.063735 0.558631 20 100 0.850000 0.000000 0.590244 0.063859 0.526385 20 100 0.850000 0.000000 0.537661 0.063859 0.473802 20 100 0.850000 0.000000 0.531875 0.063343 0.468532 24 100 0.850000 0.000000 0.484166 0.066820 0.417346 24 100 0.850000 0.000000 0.694105 0.069127 0.624978 24 100 0.850000 0.000000 1.569517 0.070212 1.499304 

the rows [1,3], [4,6], [7,9] etc. have same $1 , other columns different. , want entire row minimum value of last column , exclude other 2 script did working properly.

so result wold be:

1 57 0.850000 0.000010 0.725526 0.114805 0.610721 2 57 0.850000 0.000010 1.224136 0.063005 1.161131 4 57 0.850000 0.000010 0.679327 0.062899 0.616428 8 57 0.850000 0.000010 0.374985 0.063619 0.311367 12 57 0.850000 0.000010 0.317534 0.063243 0.254290 16 57 0.850000 0.000010 0.379314 0.063865 0.315448 20 57 0.850000 0.000010 0.333159 0.063614 0.269545 24 57 0.850000 0.000010 0.335697 0.068287 0.267411 1 100 0.850000 0.000000 0.789624 0.060151 0.729474 2 100 0.850000 0.000000 2.104924 0.063320 2.041604 4 100 0.850000 0.000000 1.139739 0.062964 1.076775 8 100 0.850000 0.000000 0.656741 0.063040 0.593701 12 100 0.850000 0.000000 0.503905 0.062864 0.441041 16 100 0.850000 0.000000 0.613314 0.063025 0.550289 20 100 0.850000 0.000000 0.531875 0.063343 0.468532 24 100 0.850000 0.000000 0.484166 0.066820 0.417346 

thanks in advance

based on input , output examples in question, one-liner job:

awk 'nr%3==1{if(a)print a;a=$0;v=$nf;next}$nf<v{a=$0;v=$nf}end{print a}' file 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -