Cat'ing a multiple line file to one line

I am writing a script that is running a loop on one file to obtain records from another file.

Using egrep, I am finding matching records in file b, then outputing feilds of both into another file.

****************************
filea=this.txt
fileb=that.txt

cat $filea | while read line
do
egrep ^${line} > tmp.$$
COUNT=`wc -l tmp.$$`
if [ -s tmp.$$ ]
then
echo "${line}`cat tmp.$$`" >> output.txt
fi
done
******************************
In the instance that tmp.$$ is 2 or more lines, how do I get all the lines on the same line? I know by looking at the example above, there are better ways to do it, however, I have to output different things based on the number of results in $COUNT. Thanks in advance!

## untested
IFS='
'
set -f
while read -r line
do
   result=$( egrep "^${line}" "$fileb" )
   set -- $result
   COUNT=$#
   {
      printf "%s " $result
      echo
    } >> "$outfile"
done < "$filea"