首页 > 解决方案 > Linux - Diff number of lines in 2 set of files

问题描述

I have 2 folders which contains 2 set of files.

Folder1

input1.csv
input2.csv
...

Folder2

output1.json
output2.json
...

Ideally, the number of lines in input1 should be same as output1, the number of lines in input2 should be same as output2, and so on.

I need a Linux command to check this automatically and tell me which files are different.

Basically,

If wc -l input1 == wc -l output1, 
    then skip;
else
    show input1 file name (or output1 file name)

repeat for all other files.

How can I achieve this?

标签: linux

解决方案


这样的事情可能会有所帮助

arr=("1.in" "2.in")
arr2=("1.out" "2.out")

for i in ${!arr[@]}; do  
  v_in=$(wc -l < ${arr[$i]}) ; 
  v_out= $(wc -l < ${arr2[$i]}) ;

  if [ v_in -ne v_out ] then
     echo "not equal"
  else
     echo "equal"
  fi
done

推荐阅读