On Tue, 10 Mar 2009, OnTheEdge wrote:
I'm having a problem getting this to work. I'm currently doing this using a
file instead of an array, but it is too slow. Here's what I'm trying to do:
For each record in my main array (array1), I want to get a match out of
array2 and append it to the array1 record. After I get the match, I want to
delete that record from array2.
For example, array2 looks something like this:
Ohio Columbus
Ohio Cleveland
Texas Dallas
Texas Austin
I want to find the first occurrence of 'Ohio' and append Ohio and Columbus
to the array1 record. Then I want to remove the 'Ohio Columbus' record from
the array so I don't pick it up the next time I search on Ohio.
match=${1:-Ohio}
n=0
while [ $n -lt ${#arra...@]} ]
do
case ${array2[$n]} in
*"$match"*)
array1[${#arra...@]}]=${array2[$n]}
unset array2[n]
break
;;
esac
n=$(( $n + 1 ))
done
printf "%s\n" "${arra...@]}"
echo
printf "%s\n" "${arra...@]}"
--
Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>
========= Do not reply to the From: address; use Reply-To: ========
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)