ksh : need to store the output of a awk command to a array

I have awk command :

 awk -F ' ' '{ print $NF }' log filename

And it gives the output as below:

06:00:00
parameters:
SDS
(2)
no
no
no
no

doc=4000000000).


information:
0
5898
5898
06:06:25

The problem is i need to save this in a array.

For example, when print or echo $array[0]
i should get 06:00:00 and similarly

$array[1] = parameters:
.
.
.
$array[n] = 06:06:25

my end goal is to print them using a print statement i.e

printf("start time: %d  and end time: %d", array[0], array[n]")

Output:

start time:06:00:00 and end time:06:06:25

Kindly help...

How about

array=( $(awk -F ' ' '{ print $NF }' log filename) )
1 Like

I had tried this earlier but i was getting this error

ksh: 0403-057 Syntax error: `(' is not expected.

A bit surprising. From this site's ksh(93) man pages:

What ksh version do you use?

I use ksh88 version

I can't help, then. Sorry.

$ set -A arr parameters: 06:06:25
$ print ${arr[0]}
parameters:
$ print ${arr[1]}
06:06:25

So, if you want elements separated by white spaces:

set -f
set -A array $(awk '{ print $NF }' filename)
set +f