how to compare file line by line with awk

im a newbee to unix.

I have a requirement to compare two files with awk.
file1.txt
a
b
c
d
e

file2.txt
a
b
d
e

here i want to compare each line in file1 with corresponding line in file2 and prinf the line with difference. ie to check

required result as shown below
a=a (dont print since records are same)
b=b (dont print since records are same)
c=d (print "diff" or any text since records are different)
d=e (print "diff" or any text since records are different)
e=null (print "diff" or any text since records are different)

I have gone through many programs in forum and i could get only scripts which lookup each value in file1 exists in file2, which is not my requirement.

Appreciate your help in advance

Thank
Kiran :b:

Try this awk 1 liner...

awk '{if(FNR==NR){f1[NR]=$0;m++}else{f2[FNR] = $0; n++};t=m>n?m:n}END{for(i=1;i<=t;i++) printf("%s",f1!=f2?i":  diff\n" : "")}' file1 file2

Your sample data files have an unequal number of lines but you did not state how to handle that. Is that a typo? If not, should comparison stop when the shorter file's end is reached? Or should the shorter file be treated as if it had enough empty lines to match the excess lines of the longer file? Or perhaps that should just be considered a match?

The following code uses paste, which treats a shorter file as if it had empty lines after end-of-file; it assumes that there are no tab characters in your lines (if there are, a different delimiter is required); and it prints out a line number when there's a difference.

paste f1 f2 | awk -F'\t' '$1 != $2 {print NR}'

Regards,
Alister

Thanks a lot alister

It is not typo. It should consider this as empty line and continue to compare.
I am generating files daily and i am comparing files generated today and on any previous days.
The data in the files are generated in sorted order, so i need to compare files to find the missing/changed line/new entry.

@shamrock: thank you for your quick response. i will test this out today.