Reading each item from a formatted file

Hi,
I have a file generated like this -

  1. Fire SQL and store the formatted output in a temp file

echo "select path, empid, age from emp_tbl" | /usr/sql emp_db 2 > count_file | grep vol > tempFile

  1. The tempFile looks like this after the above statement

/vol/emp1 0732 25
/vol/emp2 0745 26

My requirement is to read each "column" of this temp file ? How can I do that ? :confused:

Thx a lot in advance. Kindly help.

Use cut like this:

cut -d ' ' -f 2 tempFile

produces:

0732
0745

Hi,
I am a totally newbie to Solaris. So, can you tell me how do use this inside a script. I ran this from the shell directly, but it does not work.

Something like this:

while read column1 column2 column3
do
 # do something with $column1
 # do something with $column2
 # do something with $column3
 .
 .
done <  tempFile

Try this :

awk '{print $2}' tempFile

Hi Jai,
That was great. It worked. :slight_smile: Can you explain this commaned too :o ?

$2 - Indicates print the second field of tempFile. Space is default delimiter.

Hi Jai,
Now this has to be put in a while loop and output of the awk has to be captured in a variable for each line. How do i do that ?

I hope below is your requirement, If not pls let me know.

while read le
do
    echo $le > file1.txt
    var=`awk '{print $2}' file1.txt` 
    echo "Second value is : $var"
done < tempFile

Hi Jai,
Will keep you posted ! I am trying out the script. Thanks for the kind help.