Solução estendida tr
+ sort
+ paste
+ comm
:
VAR1="a2,a3,a4,a5,a6,a1"
VAR2="a1,a2,a6,a4,a7,a8"
temp1="$VAR1"
temp2="$VAR2"
VAR1=$(comm -23 <(tr ',' '\n' <<<"$temp1" | sort) <(tr ',' '\n' <<<"$temp2" | sort) | paste -d',' -s)
VAR2=$(comm -13 <(tr ',' '\n' <<<"$temp1" | sort) <(tr ',' '\n' <<<"$temp2" | sort) | paste -d',' -s)
Resultados:
$ echo "$VAR1"
a3,a5
$ echo "$VAR2"
a7,a8