Grouping and finding max using awk -


the data needs grouped, each group having 6 values, , needs find max in each group.

data:

0.0759313 0.0761037 0.0740772 0.0736791 0.0719802 0.0715406 0.0828038 0.0826728 0.0802384 0.0798476 0.0785342 0.0777939 0.0738756 0.0733486 0.0709046 0.0707067 0 0 

used awk statements, not getting result.

awk '{for(x=i+1;(x<=(i+5))&&(x<=nf);x++){a[++y]=$x;if(x==(i+5)){c=asort(a);b[z++]=a[c];i=i+6;y=0}}}end{for(j in b) print b[j]}' 

i go this:

awk 'nr % 6 == 1 || $0 > max { max = $0 } nr % 6 == 0 { print max }' file 

always set max first value in each group of six, or if value greater current maximum. @ end of each group, print value.

you may want include additional logic deal printing maximum of last few numbers, in case number of lines not divisible 6:

end { if (nr % 6 != 0) print max } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -