If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Arrays

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-29-03, 15:30
jestrada10103 jestrada10103 is offline
Registered User
 
Join Date: Oct 2002
Posts: 39
Arrays

Hello,

I have two arrays

arrayA[x]
arrayB[y]

In arrayA I have 20 procedures
In arrayB I have 2 procedures that need to be excluded from arrayA

How can I remove these from arrayA, the data stored in arrayB will be the array number (e.g. x) that needs to be excluded from my processes...

Any ideas would be great.. I'm doing this in korn shell...
Reply With Quote
  #2 (permalink)  
Old 06-02-03, 11:44
jestrada10103 jestrada10103 is offline
Registered User
 
Join Date: Oct 2002
Posts: 39
Tek-tips.com helped provide this solution.. FYI:

set -- ${arrayA[@]} # set positional parameters to elements of arrayA

integer subb=0

for i in $@ # for each parameter (ie $1 $2 $3 ...)
do
subb=0
while : #endless loop
do
# if there is a match, we want to drop this element
[[ $i = ${arrayB[subb]} ]] &&
break #jump out of THIS loop
(( subb += 1 ))
#if we've tested all elements of arrayB, then we have no match
[[ $subb -ge ${#arrayB[*]} ]] &&
{
#so we build a new variable containing all elements of arrayA that we want to keep.
NewString=" $NewString $i"
break
}
done
done
set -A arrayA $NewString # recreate arrayA


${#arrayB[*]} evaluates to number of array elements
${arrayA[@]} evaluates to all array elements
${arrayA[*]} evaluates to all array elements
${arrayB[subb]} evaluates to the array element indexed by $subb

Once you have created an array, you cannot "remove" any elements, or insert any new ones.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On