bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delete elements from an array...


From: Chris F.A. Johnson
Subject: Re: delete elements from an array...
Date: Tue, 10 Mar 2009 15:21:38 -0400 (EDT)
User-agent: Alpine 1.00 (LRH 882 2007-12-20)

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 address@hidden ]
do
  case ${array2[$n]} in
    *"$match"*)
         address@hidden
         unset array2[n]
         break
         ;;
  esac
  n=$(( $n + 1 ))
done

printf "%s\n" "address@hidden"
echo
printf "%s\n" "address@hidden"

--
   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)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]