array

hi to all ....
i have txt file , tat contains list of file name ... i hav to put it into the array ..
say list.txt
in tat
kay.ldf
hak.ldf
warper.ldf
like tat

thanks

#!/bin/ksh
set -A array `awk '{printf("%s ", $0)}' list.txt`

Hey

I am also trying to get this
How can we read the values from array after storing the text file into an array

Thanks

Simple Ex in ksh:

> ARRAY[1]="HOLA"
> ARRAY[2]="ADIOS"
> i=1
> j=2
> echo "${ARRAY[${i}]} ${ARRAY[${j}]}"
HOLA ADIOS

Hi Klashxx
How u doing thanks for the answer

My script is this

#!/usr/bin/ksh
DIRNAME=`dirname $0`
export columnIdFile="colids.txt"
LOGFILE=$DIRNAME/cvs_users_defaults.log
TIME=`date`
#checks to see if the log files is present, if not then creates it
if [ -a $DIRNAME/cvs_users_defaults.log ]
then
:
else
touch $DIRNAME/cvs_users_defaults.log
fi

#Checking to see if a data file(colids.txt) exists for a load.
if [ -a $DIRNAME/$columnIdFile ]
then
INCOLFILE=$columnIdFile;
echo "Using file $INCOLFILE as input for column id";
echo " ";
echo "Started Process on $TIME" >> $LOGFILE
echo "Calling procedure to initialize users"

for colId in `cat $INCOLFILE`
do
echo "Storing User Defaults for User " $colId >> $LOGFILE

            integer i=0
            awk '\{print $1\}' colids.txt | while read item; do
             myarray[$i]=$item
             i=$i\+1                
            done

            integer j=0
            if [[ $j -lt 5 ]]; then
            print $\{myarray[j]\}                
            echo "$\{myarray[$\{j\}]\}"
            j=$j\+1
            fi

done
#Here I am trying to print or echo the values in the array myarray but #couldnot get the values
#Is there something wrong I am doing Can you plz help me out

#rename the file after processing
logtime=`date "+%y%m%d%H%M%S"`
newUserFile="cvs_users_processed_"$logtime".txt"
# mv $userFile $newUserFile

  echo "Ending process of setting user defaults at $TIME "  >> $LOGFILE
  echo "Check the log file at $LOGFILE"
  exit 0

else
#IF "custsoncologyusers.txt" file does not exist in DIRNAME then end grace
fully
echo "No user default file ($userFile) is available to load"
echo "No user default file ($userFile) is available to load" >> $LOG
FILE
echo "Ending user default process with a return code 0 at $TIME" >> $LOG
FILE
exit 0
fi

Thanks
Pinky

Ok , try this (ksh):

i=0
awk '{print $1}' colids.txt | while read item
                                      do
                                           myarray[${i}]=${item}
                                           (( i+= 1 ))               
                                      done

j=0
while (( j < i ))
do
     echo "${myarray[${j}]}"
      (( j += 1 ))
done

Regards

Hi I tried to assign the array as you suggested
could able to assign but could not read them out of the loop

I was trying to do this instead

myfile has this data

molly
mic

typeset -i cnt=0
while read line
do
my_user_id[$cnt]=$line
((cnt = cnt + 1))
done < myfile

select linefromfile in ${my_user_id[@]}
do
echo $linefromfile
done

when I looked at the output I am getting
1)molly
2)mic
#?

why am I getting the #? at the end of the output
it's an error I guess and it's stopping the rest of the program to work

can any body explain why am I getting #? and how to get rid of it?

Thanks
Pinky