I have two arrays, how would I get the list of elements that appear exclusively in the second, that are not available in the first?
Array1=( "A" "B" "C" "D" ) Array2=( "B" "E" "G" )
I need the output as Array3=("E" "G")
because E and G are not present in Array1. I used @ephemient @SiegeX answers but that is not returning what I need.
function arraydiff() {
awk 'BEGIN{RS=ORS=" "}
{NR==FNR?a[$0]++:a[$0]--}
END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}")
}
Array1=( "A" "B" "C" "D" )
Array2=( "B" "E" "G" )
Array3=($(arraydiff Array1[@] Array2[@]))