下面是逐行比较两个文件的脚本代码。希望大家多多提建议。

 
  
  1. #!/bin/bash 
  2.  
  3. CurRow=1 
  4. LastRow=`cat file1 | wc -l` 
  5.  
  6.  
  7. while [ $CurRow -le $LastRow ] 
  8. do 
  9.  
  10.     for x in `awk 'NR=='$CurRow' {print $0}' file1` 
  11.     do 
  12.          
  13.         for y in `awk 'NR=='$CurRow' {print $0}' file2` 
  14.             do 
  15.         if [ "$x" == "$y" ];then 
  16.              
  17.           echo "$x" >>result.txt 
  18.  
  19.         fi       
  20.         done 
  21.      done 
  22.      ((CurRow++)) 
  23. done