Since your list of filenames is probably unique, I would use an
associative array instead:
#Build an example array
typeset -A array
for ((c=0; c<=10000; c++)); do
array[element$c.txt]=1
done
#Build a second array containing all of the elements to be deleted
from the first array
for ((n=0; n<=5000; n++)); do
delete_elements+=(element$n.txt)
done
#For each element to be deleted, search the first array for the
element string and delete it whenever found
for delete_element in ${delete_elements[*]}; do
if (( ${array[$delete_element]} )); then
unset array[$delete_element]
fi
done
# To iterate over the associative array
for element in "${!array[@]}"; do
print "$element"
done
# Or, if you want to convert it back to a standard array
set -A array2 "${!array[@]}"
print "${array2[@]}"
On 3 October 2014 23:37, Douglas Houston <[email protected]> wrote:
> Yes - or I could write it in assembly! ;-)
>
>
> Quoting David Nicol <[email protected]> on Thu, 2 Oct 2014 13:37:49
> -0500:
>
>> On Thu, Oct 2, 2014 at 3:56 AM, Douglas Houston
>> <[email protected]
>>>
>>> wrote:
>>
>>
>>>
>>>
>>>> I have two lists of filenames, and I need to delete every entry from the
>>>> first list that appears in the second list. The way I'm doing it right
>>>> now
>>>> seems awfully slow ... can anyone tell me if there is a way to do it in
>>>> ksh
>>>> that runs faster than this does?:
>>>>
>>>
>>
>> untested:
>>
>> perl -nle 'BEGIN{ @x{`cat secondlist.txt`} = () } exists $x{$_} or print'
>> <
>> firstlist.txt >filteredlist.txt
>> mv filteredlist.txt firstlist.txt
>>
>>
>>
>> --
>> Sometimes I imply things, or include important information in pictures.
>> Without a request for clarification, I will assume I was clear, which can
>> cause later problems when I wasn't. So please ask me to clarify anything
>> that seems ambiguous. Doing so is not rude. Thank you.
>>
>
>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
> _______________________________________________
> uwin-users mailing list
> [email protected]
> http://lists.research.att.com/mailman/listinfo/uwin-users
--
Regards
Danny
_______________________________________________
uwin-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/uwin-users