Command to show unique strings in two files

how to display the unique strings in two files using shell script or commands.
I tried diff and cmp but it shows the entire line, i need only the mismatched strings.

File1:

sat,sun,mon,tue
rose,lilly,lotus
white,red,blue,green,pink

File2:

sat,sun,mon,tue
rose,sunflower,lotus
white,red,blue,green,pink

output:

something like this.
lilly (line 2, 2nd column) in file1 doesnt match with file2.

Try sth like this..

awk -F, 'NR==FNR{for(i=1;i<=NF;i++){A[i,FNR]=$i};next}{for(i=1;i<=NF;i++){if(A[i,FNR]!=$i){print A[i,FNR],"(line "FNR","i" Column) in file1 does not match with file2";}}}' file1 file2

Pamu: Its throwing error..

bash-3.00$ awk -F, 'NR==FNR{for(i=1;i<=NF;i++){A[i,FNR]=$i};next}{for(i=1;i<=NF;i++){if(A[i,FNR]!=$i){print A[i,FNR],"(line "FNR","i" Column) in file1 does not match with file2";}}}' file1.txt file2.txt

awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

Use /usr/xpg4/bin/awk or nawk on Solaris.

1 Like

Many thanks... It works perfectly... tested on both solaris and linux :-).