I found quite a few posts on this but couldn't put together the pieces to solve my issue. So say I have two arrays:
array1=( adir bdir anicedir )
array2=( adir anice )
I would like to have a third array like so
array3=( adir anicedir )
More specifically if the first 5 characters of the i-th element in array2 match the first 5 characters of any element in array1 then substitute array2[i] with array1[i]