#!/bin/ksh
# Use the Set command to designate a variable as a
# simple, 1 dimentional Array.
set -A line_array
# Designate an incoming File Name
file_name='test.dat'
# I use simple array index variables. Arrays in the
# k-shell start with an index of 0.
i=0
# Read a line of data from the Incoming File into the
# variable file_line. Note that the data file is
# redirected into the loop on the "done" command
# at the end of the loop.
# The array, line_array, is indexed by the value of i.
# The data from the File is saved in the next array
# element and the Index , i, is incremented.
while read file_line
do
line_array=${file_line}
let i=${i}+1
done < ${file_name}
# Now that you have the data in the Array you can
# do whatever processing you want on it by addressing
# any of the array elements. In this sample we are
# assuming that the data is in the form of x:y and
# we want to display each value of x.
# Reset the Index to the first element.
i=0
# In order to loop thru each value of the array,
# we check to make sure that the Array Index
# is less than or equal to the total number of array
# elements.
# For our sample we display everything to the left of
# the ':' character.
# Remember to increment the Index value.
while [ ${i} -le ${#line_array[*]} ]
do
echo ${line_array}|cut -f1 -d:
let i=$i+1
done
# Use the Set command to designate a variable as a
# simple, 1 dimentional Array.
set -A line_array
# Designate an incoming File Name
file_name='test.dat'
# I use simple array index variables. Arrays in the
# k-shell start with an index of 0.
i=0
# Read a line of data from the Incoming File into the
# variable file_line. Note that the data file is
# redirected into the loop on the "done" command
# at the end of the loop.
# The array, line_array, is indexed by the value of i.
# The data from the File is saved in the next array
# element and the Index , i, is incremented.
while read file_line
do
line_array=${file_line}
let i=${i}+1
done < ${file_name}
# Now that you have the data in the Array you can
# do whatever processing you want on it by addressing
# any of the array elements. In this sample we are
# assuming that the data is in the form of x:y and
# we want to display each value of x.
# Reset the Index to the first element.
i=0
# In order to loop thru each value of the array,
# we check to make sure that the Array Index
# is less than or equal to the total number of array
# elements.
# For our sample we display everything to the left of
# the ':' character.
# Remember to increment the Index value.
while [ ${i} -le ${#line_array[*]} ]
do
echo ${line_array}|cut -f1 -d:
let i=$i+1
done