Error running the script.... Help needed. Please

I have another Question:

I tried to run the following script: (I actually wanted to print out the second field in the text field.)

#!/usr/bin/ksh
set -x
readfile=/dir1/data.txt

cat $readfile | while read line
do
x = `echo $line|awk '{print $2}'`
echo $x
done

But, it shows the following error. It is unable to read the 'x' value.

# ./readData
+ readfile=/dir1/data.txt
+ cat /dir1/data.txt
+ read line
+ awk {print $2}
+ echo skhfkjshf 24343
+ x = 24343
./readData[7]: x:  not found
+ echo

+ read line
+ awk {print $2}
+ echo jsdhfklhd 94890
+ x = 94890
./readData[7]: x:  not found
+ echo

I have given all the permissions.. chmod 777 readData

Please help me out in solving this issue.

Thanks in advance.

The assigment to the variable x may not contain spaces.

x=`echo $line|awk '{print $2}'`

You can achieve the same effect with just awk.

awk '{print $2}' /dir1/data.txt

Or with just shell:

#!/usr/bin/ksh
set -x
readfile=/dir1/data.txt

cat $readfile | while read junk1 x junk2 
do
        echo "${x}"
done

@ Scrutinizer:

Thank you very much...

It did work for me...