我测试了这个,它有效。每个文件中都没有维护行的顺序,但是您在评论中说您已经在应用sort,所以这没关系。这是一个小迂回,但它确实有效:
   #!/bin/bash
   #The number of files you have, named like file1.txt, file2.txt, etc.
   # If named otherwise, cahnge the definition of variable "file" in the loop below.
   NUM_FILES=3
   #These files will be created and removed during the script, so make sure they're
   # not files you already have around.
   tempfile1="_all.txt"
   tempfile2="_tmp.txt"
   sort -u file1.txt > file1out.txt
   cat file1out.txt > $tempfile1
   for i in $(seq 2 $NUM_FILES)
   do
       prev=$((i-1))
       pofile="file${prev}out.txt"
       file="file$i.txt"
       ofile="file${i}out.txt"
       echo "Input files: $file $pofile"
       echo "Output file: $ofile"
       cat $tempfile1 $pofile > $tempfile2
       sort -u $tempfile2 > $tempfile1
       sort -u $file | comm -23 - $tempfile1 > $ofile
   done
   rm -f $tempfile1 $tempfile2