Compare 2 colums in two files

Hi ,

I am trying to write a part in shell script. I have two files with one column each and would like to output it to a new file giving the records which are different.Pls help experts.

File1
Column name
11
12
13
14
18
 
File2
Column name
11
12
14
17
19
20
 
File 3
Column Name Column name
13                   17
14                   19 
18                   20
 

An awk approach:

awk '
        NR == FNR {
                A[$1]
                C[$1]
                next
        }
        {
                B[$1]
                C[$1]
        }
        END {
                for ( k in C )
                {
                        if ( !( k in A ) )
                                T[++i] = k
                        if ( !( k in B ) )
                                R[++j] = k
                }
                n = ( i > j ? i : j )
                for ( k = 1; k <= n; k++ )
                        print T[k], R[k]

        }
' OFS='\t' file1 file2
1 Like

If the files are sorted, try:

comm -3 file1 file2
1 Like