Detect differences in two files

All,

I have two csv files, the format of which are exactly the same.

I would like to find differences between the two files but would like to identify the difference as opposed to just printing a different line.

For exmaple

File 1

xxx,yyy,zzz,1,2,3
111,222,333,xxx,yyy

File2

xxx,yyy,zzz,8,2,4
999,222,333,xxx,zzz

I would like a script which identifies and logs that fields 4 and 6 are different in line 1 and fields 1 and 5 are different in line two.

I was thinking of an awk script, can awk process two files and if so how are fields in each file referenced.

Thanks for your help

diff file1.txt file2.txt

A diff only gives me lines where a difference occurs.

I would like to also identify the field(s) in the line which are different

awk -F, '{
  getline s < "file2"
  split(s,a,",")
  m="Line " NR ":"
  for(i=1;i<=NF;i++){
    if(a != $i){
      m=m " field " i
    }
  }
  print m
}' file1
2 Likes

Franklin,

Perfect, exactly what I wanted.

Thanks for your help.