i have two array of numbers, first array have all numbers while the second has a subset of first one, how can i write a script to find the missing number which exist in the first array but not in the second array?
Array 1: [0, 1, 2, ..79] Array 2: [1, 12, 33, 54,60, 71]
i googled around and tried different approaches i found but none of them worked
1.
declare -a array3
for i in "${array1[@]}"
if [[ "${array2[@]}" =~ "$i" || "${array2[${#array2[@]}-1]}" == "$i" ]]; then
else
array3+=("$i")
fi
done
2.
array3=()
for i in "${array1[@]}";do
skip=
for j in "$array2[@]";do
[[ $i == $j ]] && { skip=1; break; }
done
[[ -n $skip ]] || array3+=("$i")
done
declare -p array3
i m new to bash script, please help!
$iforarray1and$jforarray2, and you will either find that$array1[$i]is smaller than$array2[$j, or equal to it, or larger than it. If the number in$array1[$i]is smaller, print it and increment$i; if the values are equal, increment both$iand$j; if it is larger, increment$j. Stop when you reach the end of either array.