Redirect output from SQL to unix variable

Hi,

I have a requirement to store oracle sqlplus output to some unix variable, count the records and then print the output on the screen.

Can you please point me to any sample program for reference purpose.

Thanks a lot for your time.