#!/usr/bin/ksh #A program to query information from the tables Orders.csv and Customers.csv #Set up an array called "Cust" with these elements: jchen13 msurjan dtrinh4 #kchuang ahernan9 set -A Cust jchen13 msurjan dtrinh4 kchuang ahernan9 #Test out the result. Note that to call the element of an array, we have to #enclose the array's name with the curly brackets as follow: echo "The elements in the array Cust are:" echo ${Cust[*]} #This will show the entire array as seperate string. Each #element is a string by itself. echo ${Cust[@]} #This will also show the entire array but as an entire string. echo ${#Cust[*]} #This will show the number of elements in the array. echo ${Cust[2]} #This will show the 3rd element in the array. echo "================================" index=0 #Initialize up the index of the array. #Loop thru the elements in the array Cust. for element in ${Cust[*]} do echo ${Cust[$index]} #We need to increment the count "index" and here is how to do it: ((index=$index + 1)) done last > user.txt #Store the logged on users' names in the file user.txt. #You may need to pass the argument into the awk command, and here is how: #Enclose the variable in the single quotes. # awk -F, '{if($1 ~/'${Cust[0]}'/) print}' user.txt #If the variable is a string and the string contains more than ONE word, then #we HAVE TO ENCLOSE the variable within a pair of double quotes. For example: status="logged in" #You may NOT get any data back, depends on how you set up the user.txt file. awk -F, '{if($1 ~/'"$name"'/) print}' user.txt