bash - Subtract single largest number from multiple specific columns in awk -


i have comma delimited file looks

r,f,te,k,g,r 1,0,12,f,1,18 2,1,17,t, ,17 3,1,  , ,1, 4,0,15, ,0,16 

there items missing, first row header want ignore. wanted calculate second smallest number in specific columns , subtract elements in column unless value in column minimum value. in example, want subtract second minimum values columns 3 , 6 in example. so, final values be:

r,f,te,k,g,r 1,0,12,f,1,1 2,1, 2,t, ,0 3,1, , ,0, 4,0, 0, ,0,16 

i tried individually using single columns , giving hand-coded thresholds make second largest

awk 'begin {fs=ofs=",";  }; { min=1000000;   if($3<min && $3 != "" && $3>12) min = $3;   if($3>0) $3 = $3-min+1;  print}  end{print min}  ' try1.txt 

it finds min alright output not expected. there should easier way in awk.

begin{     fs=ofs="," } {     if(nr==1){print;next}     if(+$3)a[nr]=$3     if(+$6)b[nr]=$6     s[nr]=$0 } end{     asort(a,c)     asort(b,d)     for(i=2;i<=nr;i++){         split(s[i],t)         if(t[3]!=c[1]&&+t[3]!=0)t[3]=t[3]-c[2]         if(t[6]!=d[1]&&+t[6]!=0)t[6]=t[6]-d[2]         print t[1],t[2],t[3],t[4],t[5],t[6]     } } 

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 -