shellfilecompare

Compare 2 files NOT line by line in shell


I need to compare two files NOT line by line ,rule out common lines,then have an output with everything that is different using shell commands .

Example:

file 1:

5
124
346
12
65
8
78

file 2:

10
23
129494
5
493
124
4999
346

Output:

12
65
8
78
129494
943
4999

Thank you

Ok let me add some details: I have some files including pairs of IPs.

Example:

file 1:

55.4.56.11 10.22.123.43 10.22.123.43 147.34.123.43 147.34.23.2 23.124.251.1

file 2:

123.4.23.89 121.45.60.0 121.45.60.0 0.0.0.0 120.3.2.129 45.55.68.09 45.55.68.09 66.67.23.111 55.4.56.11 10.22.123.43

So in this example,i need as output,every line of both files except : 55.4.56.11 10.22.123.43

That means i cant use numerical comparison.Also sorting out the files doesn't help,cause the may have different number of rows.I need something like "global" comparison for both files. If you guys need more details,i will gladly edit my post further. Thank you for your time. (I cant make 2nd example look like the first,i dunno why,but suppose there is a newline after every two IPS)


Solution

  • Using grep:

    grep -xv -f f2 f1 && grep -xv -f f1 f2
    12
    65
    8
    78
    10
    23
    129494
    493
    4999