Well like others I have a start for you but it would need some tweaking. Using the 3 files you presented I believe my output looks correctish
To give you an idea of what needs work, my script finishes when file1.txt has finished being read. A downside to this is that if there are corresponding results
in file2 or file3 they will not get printed
Code:
#!/bin/bash
exec 4<"file1.txt"
exec 5<"file2.txt"
read -r line <&4
echo "$line"
keep="${line#>}"
while read -r line
do
if [[ "${line:0:1}" == ">" ]]
then
[[ -n $line2 ]] || read -r line2 <&5
echo "$line2"
while read -r line2
do
[[ "${line2:0:1}" == ">" ]] && break
echo "$line2"
done<&5
awk -vcheck="$keep" '$0 ~ gensub(/[[:blank:]]+.*$/,"","g",check){print RS $0;f=1}END{if(!f)print "NO SIGNIFICANT RESULTS FOUND"}' RS="Query=" file3.txt
keep="${line#>}"
fi
echo "$line"
done<&4
exec 4<&- 5<&-