1

I need help with bash. I have two array:

Array1=(1 2 3 4 5 6 7)
Array2=(2 5 7)

I need remove items from array1 which are in Array2. Result should be

Array3=(1 3 4 6).

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
user3468921
  • 561
  • 2
  • 8
  • 26
  • read the answers in referenced questions. – Kent Aug 16 '17 at 13:25
  • I can see another similar question here. https://stackoverflow.com/questions/2312762/compare-difference-of-two-arrays-in-bash – nagendra547 Aug 16 '17 at 13:33
  • It's not quite a duplicate, but [BashFAQ #36](http://mywiki.wooledge.org/BashFAQ/036) is also relevant. – Charles Duffy Aug 16 '17 at 16:40
  • One should also consider using associative arrays to avoid the need to recurse -- the O(n*m) performance characteristics of the code given in the self-answer is really quite horrid. – Charles Duffy Aug 16 '17 at 16:41
  • Aside: Answering your own question is welcome here, but answering your own question *by editing that answer into the question itself* is not. This "privileges" answers, such that they can't be voted or commented on separate from the question itself, and prevents mechanisms for putting good answers first from being effective. – Charles Duffy Aug 16 '17 at 16:42

0 Answers0