Advertisement
Guest User

Untitled

a guest
Aug 13th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # the two original arrays
  2. bash-4.1$ array1=(a b c d)
  3.  
  4. bash-4.1$ array2=(a h c d l k)
  5.  
  6. # lookup array
  7. bash-4.1$ declare -A array2rev
  8.  
  9. bash-4.1$ for i in "${!array2[@]}"; do array2rev["${array2[i]}"]="$i"; done
  10.  
  11. # checking elements in the lookup array
  12. bash-4.1$ for i in "${array1[@]}"; do echo "element $i of first array is $([[ "${array2rev[$i]}" ]] || echo 'NOT ')present in the second array"; done
  13. element a of first array is present in the second array
  14. element b of first array is NOT present in the second array
  15. element c of first array is present in the second array
  16. element d of first array is present in the second array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement