Hope I got this correct. You have the result of something and you want get it line by line in a variable.
Instead of redirecting it to file try piping it to a while read loop.
First of all there's no need to
cat <filename> |grep <pattern>
grep <pattern> <filename>
it's quicker. piping always costs.
SO try something like
grep <pattern> <filename> | while read a; do ...... ; done
The variable $a will get the input line by line