how to read each letter from file and store it in variable.

Dear friends,

i am writing csh script

i have one dat file containing following data.like this.
08FD3 03A26 000FA0 FFFF0 BBA0F 00000 00000

from the above file i want to read each letter and store it in one variable.
how it is possible.

please help

# !/usr/bin/ksh

set -A arr
word="08FD3 03A26 000FA0 FFFF0 BBA0F 00000 00000 "
len=${#word}

i=1
while [ $i -le $len ]
do
arr[$i]=`echo $word | awk '{ print substr($0, '$i', 1) }'`
i=$(($i + 1))
done

#Print - Method I
i=1
while [ $i -le $len ]
do
print ${arr[$i]}
i=$(($i + 1))
done

#Print - Method II
print ${arr[*]}

exit 0

You can use fold -1 to split, e.g in ksh....

word="08FD3 03A26 000FA0 FFFF0 BBA0F 00000 00000"
echo $word | fold -1 | awk NF | while read one
do
  printf '%s = %04d\n' $one $(echo "ibase=16;obase=2;$one"|bc)
done

...which gives...

0 = 0000
8 = 1000
F = 1111
D = 1101
3 = 0011
0 = 0000
3 = 0011
A = 1010
2 = 0010
6 = 0110
: etc

Dear ygor,

thank u for your reply,

but according to your code you assiged the data to one variable.

from that variable you are spliting the data.

but my requirement is i have this data in one file.

from that file i have to read each hexadecimal data and convert it in to binary.

i hope that my problem is understood to u.

regards
rajan

dear ygor,

i am using csh so please give me the syntax compatible to csh

I don't do csh.

ok friend,

if you dont use csh then please give me the code in sh . no problem

waiting for reply.

regards
rajan

I already did.