Compare two text files command line (Linux)
- February 11th, 2010
- Write comment
You’ll first need to sort the two files into new temporary files that are ordered:
sort -o tmp1.txt File1.txt && sort -o tmp2.txt File2.txt
You can then compare the new temporary files:
lines common to both files:
comm -12 tmp1.txt tmp2.txt
lines only in file 2
comm -13 tmp1.txt tmp2.txt
lines only in file 1
comm -23 tmp1.txt tmp2.txt