假如一个文本文件file是这样的,里面全部是数字

 

 

 
  
  1. 740     15972   18307   16248   17862   29009   13603   2239    14893   11235   19566   13175   3291    14677   29570   15409   8693    19836   1979    13319   28403 
  2.  
  3. 14432   5202    577     30424   25355   30710   31333   7042    23863   9974    7782    7068    28282   24031   24930   24524   4867    27169   6649    16103   13968 
  4.  
  5. 19824   19394   28645   16627   2036    4570    3696    4016    17889   32100   18448   23091   32678   16104   15678   30620   14669   22721   21716   24644   30504 
  6.  
  7. 28784   20159   21767   20946   11915   26635   15348   18565   9970    29316   5622    29365   25193   22249   31402   29764   25946   2650    14885   25278   21099 

 

编写一个shell脚本用来找出这个文件中最大数字和最小数字
 
 
 
   
  1. #!/bin/bash 
  2. MAX=`for i in $(cat file);do echo $i;done|sort -nr|head -1` 
  3. MIN=`for i in $(cat file);do echo $i;done|sort -nr|tail -1` 
  4. echo "the Max number is : $MAX" 
  5. echo "the Min number is : $MIN"