column operation using awk

I have atxt file,i want to perform some operation on 3rd coulmn

 900.00000               1           1           1
   500.00000    
   500.00000    
  100000.000    
      4
      4
  1.45257346E-07   899.10834       67.780083      -3.0000000       6.9356270          0      4
  3.36595804E-07   854.32300       67.787216      -2.0000000      -5.6963296          0      4
  4.59328561E-07   764.32300       67.784538       2.0000000      -3.8667135          0      4
  8.10901852E-08   809.10840       67.784058       3.0000000       5.9845576          0      4

1: I want to find the minimum in the third column and then subtract all the elements of 3rd column with that minimum

i am using the below code to obtain the minimum ( the code is working good )

awk 'NR==7{min=$3;max=$3}NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END {delay=max-min; print ""min" "max" "delay}' $inputfile > $outputfile 
desired output file:
1.45257346E-07   899.10834    0
3.36595804E-07   854.32300    0.0071
4.59328561E-07   764.32300    0.0045
8.10901852E-08   809.10840    0.0040

2: is is possible to arrange the rest two columns ($1 and $2 based on the ascending order of the 3rd column

What do you think about the following:

# testFile=TestFile.txt
# minValue=`awk 'NR==7{min=$3;max=$3}NR>7{if ($3>max){max=$3};if ($3<min){min=$3}}END {print min}' "${testFile}"`
# awk 'NR>6{print $1 " " $2 " " ($3-"'${minValue}'")}' "${testFile}" | sort -k3
1.45257346E-07 899.10834 0
8.10901852E-08 809.10840 0.003975
4.59328561E-07 764.32300 0.004455
3.36595804E-07 854.32300 0.007133

Regards!

$
$
$ cat f2
 900.00000               1           1           1
   500.00000
   500.00000
  100000.000
      4
      4
  1.45257346E-07   899.10834       67.780083      -3.0000000       6.9356270          0      4
  3.36595804E-07   854.32300       67.787216      -2.0000000      -5.6963296          0      4
  4.59328561E-07   764.32300       67.784538       2.0000000      -3.8667135          0      4
  8.10901852E-08   809.10840       67.784058       3.0000000       5.9845576          0      4
$
$
$ awk 'NR==7 {min=$3; x[1]=$1"~"$2"~"$3; n=1}
     NR>7  {if ($3<min){min=$3}; x[NR-6]=$1"~"$2"~"$3; n=n+1}
     END {for(i=1; i<=n; i++) {split(x,y,"~"); print y[1],y[2],y[3]-min}
         }' f2 | sort -k3
1.45257346E-07 899.10834 0
8.10901852E-08 809.10840 0.003975
4.59328561E-07 764.32300 0.004455
3.36595804E-07 854.32300 0.007133
$
$
$

tyler_durden

And yet another one :):

awk 'NR==FNR{if(NR==7){min=$3;next} if($3 < min){min=$3};next}
FNR > 6{print $1, $2, $3-min | "sort -nk3"}' file file

Another one using Perl:

$ 
$ 
$ cat -n f2
     1	 900.00000               1           1           1
     2	   500.00000
     3	   500.00000
     4	  100000.000
     5	      4
     6	      4
     7	  1.45257346E-07   899.10834       67.780083      -3.0000000       6.9356270          0      4
     8	  3.36595804E-07   854.32300       67.787216      -2.0000000      -5.6963296          0      4
     9	  4.59328561E-07   764.32300       67.784538       2.0000000      -3.8667135          0      4
    10	  8.10901852E-08   809.10840       67.784058       3.0000000       5.9845576          0      4
$ 
$ 
$ 
$ perl -lane '$.>=7 && do {push @x,"$F[0] $F[1] $F[2]"; $m=$F[2] if $.==7 or $F[2]<$m};
              END {for(@x){@y=split; $y[2]-=$m; push @z,"@y"}
                   @m = sort {(split " ",$a)[2] cmp (split " ",$b)[2]} @z; print for(@m)}' f2
1.45257346E-07 899.10834 0
8.10901852E-08 809.10840 0.00397499999999695
4.59328561E-07 764.32300 0.00445499999999299
3.36595804E-07 854.32300 0.00713299999999606
$ 
$ 

tyler_durden