Bash while loop to compare two files and print line number
问题 I have file1: A B C D I have file2: B C I want to use a while read loop to go through both files compare them and print out the line number of file1 for any matching lines. COUNT=0 while read line do flag = 0 while read line2 do COUNT=$(( $COUNT + 1 )) if ( "$line" = "$line2" ) then flag = 1 fi done < file1 if ( flag -eq 1 ) then echo $COUNT > file3 fi done < file2 However I get an error: B command not found Please could someone let me know where I have gone wrong. Thanks. 回答1: There are