Operating System - HP-UX
1748184 Members
3888 Online
108759 Solutions
New Discussion юеВ

How read data onto an array

 
SOLVED
Go to solution
Klaus  Frank
Frequent Advisor

How read data onto an array

Hallo to all

some simple task is just not working:
I need to read some coordinates to an array using ksh script. Until now I tried this:

points=`cat $inputfile | grep ... | cut ... `
------- example ---------------------
echo $points # trace only
-0.00000000000052 229.37500000000000 -86.20000000000000 291.90000000000000 0.00000000000367 -86.20000000000000 281.27957
5308520 210.960466611540 (etc...)
----- end of example -----------------
now I used to go on like this:
set -A array $points

but then I get this error message:
-0.00000000000052: A specified flag is not valid for this command.

If I eliminate all "-" signs from $inputfile then the script works fine to the end.

I want to have the result as:
$array[0] -0.00000000000052
$array[1] 229.37500000000000
$array[2] -86.20000000000000

How can I get the above results even with negative numbers ?

thanks for any advises
... we all can make it with a little help ...
2 REPLIES 2
Robin Wakefield
Honored Contributor
Solution

Re: How read data onto an array

Hi Klaus,

You need to use:

set -A array -- $points

to indicate "end of arguments, beginning of data".

Rgds, Robin
Eugen Cocalea
Respected Contributor

Re: How read data onto an array

Hi,

I use /sbin/sh and it works fine with

set -A array $points

E.
To Live Is To Learn