With your shown samples/attempts only, please try following. Written and tested in GNU awk.
1st solution: This will match each set(from 1.txt and 2.txt)'s last element if they are equal then it will print the sets from both the files eg: (bb from 1.txt is matched with bb; from 2.txt in 1st set(line in case of RS is on paragraph mode) of both the file)
awk -v RS="" '
FNR==NR{
arr[FNR]=$0
next
}
{
num1=split(arr[FNR],tempArr1,"\n")
num2=split($0,tempArr2,"\n")
num3=split(tempArr2[num2],tempArr3,";")
if(tempArr3[num3-1]==tempArr1[num1]){
print arr[FNR] ORS $0
}
}
' 1.txt 2.txt
2nd solution: This considers that values of last lines of each set(from file1 and file2) could be find in anywhere(irrespective of place, like 1st solution specifically compares last position of is equal or not for both file's same set(lines)).
awk -v RS="" '
FNR==NR{
arr[FNR]=$0
next
}
{
num1=split(arr[FNR],tempArr1,"\n")
num2=split($0,tempArr2,"\n")
if(index(tempArr2[num2],tempArr1[num1])){
print arr[FNR] ORS $0
}
}
' 1.txt 2.txt
NOTE: To run program(taking example of 1st code given above here) in .awk script format, create script.awk script file and make sure it has proper permissions to run:
cat script.awk
FNR==NR{
arr[FNR]=$0
next
}
{
num1=split(arr[FNR],tempArr1,"\n")
num2=split($0,tempArr2,"\n")
num3=split(tempArr2[num2],tempArr3,";")
if(tempArr3[num3-1]==tempArr1[num1]){
print arr[FNR] ORS $0
}
}
IN both solutions Run above scipt.awk as follows:
awk -v RS="" -f script.awk 1.txt 2.txt