bestjoe 发表于 2018-8-19 10:11:31

shell脚本实现两个文件的逐行对比

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


[*]#!/bin/bash
[*]
[*]CurRow=1
[*]LastRow=`cat file1 | wc -l`
[*]
[*]
[*]while [ $CurRow -le $LastRow ]
[*]do
[*]
[*]    for x in `awk 'NR=='$CurRow' {print $0}' file1`
[*]    do
[*]
[*]      for y in `awk 'NR=='$CurRow' {print $0}' file2`
[*]            do
[*]      if [ "$x" == "$y" ];then
[*]
[*]          echo "$x" >>result.txt
[*]
[*]      fi
[*]      done
[*]   done
[*]   ((CurRow++))
[*]done
  



页: [1]
查看完整版本: shell脚本实现两个文件的逐行对比