Following onliner will do the trick :
diff -y <(printf '%s\n' "${array2[@]}") <(printf '%s\n' "${array1[@]}") | grep -Po '[\|\<\>][\t]\K[0-9]+$'
The printf
is used to print elements in separate lines. Now the diff -y
gives the output :
1 1
2 2
3 3
5 | 4
6 5
7 6
9 7
10 | 8
11 9
12 10
11
12
Now all you have to filter the numbers after the |
(or sometimes<
or >
). I used grep
for this, but sed
can be used too. If your array is not sorted, simply add sort to each printf
like this :
(printf '%s\n' "${arrayN[@]}"|sort -n)