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
Code:
cat <filename> |grep <pattern>
.
Just
Code:
grep <pattern> <filename>
it's quicker. piping always costs.
SO try something like
Code:
grep <pattern> <filename> | while read a; do ...... ; done
The variable $a will get the input line by line