Normalise trunk VLAN sets
Expand ranges and remove duplicates before comparing allowed VLANs.
A list can describe a set
The strings 10,11,12 and 10-12 describe the same VLAN membership in this teaching format. Comparing the raw strings would report a difference even though the allowed set is identical. Normalise the representation before using it as evidence of drift.
Each comma-separated token is either one VLAN number or an inclusive ascending range. Split the list, then each token, expand the small ranges and store membership under a device/port/VLAN key. Repeated tokens and overlapping ranges must produce only one row for a VLAN on that interface.
Keep expansion bounded and ordering numeric
The supplied input is already validated: canonical VLANs 1–4094, ascending ranges, and no empty tokens. A production parser must reject malformed or unreasonably large input before expansion. Here every range has at most sixteen values, so a simple loop has a clear bound.
Sort device and port as text, then VLAN numerically. Plain text order would put VLAN 100 before VLAN 20. Portable sort supports explicit fields and numeric comparison without GNU version sorting. This is a normalised collector format, not a parser for every vendor's trunk configuration syntax; native VLAN and tagged/untagged semantics require additional information.
printf 'Text order:\n';printf '100\n20\n' | sort
printf 'Numeric order:\n';printf '100\n20\n' | sort -n
Put it into practice.
Expand trunks.tsv (device_id<TAB>port<TAB>allowed) into stdout device_id<TAB>port<TAB>vlan. Inputs have unique device/port pairs and validated comma-separated single VLANs or inclusive ascending ranges; values are canonical 1–4094 and each range contains at most 16 values. Remove duplicate membership from overlapping/repeated tokens. Sort by device, port, then numeric VLAN in LC_ALL=C. Do not use vendor commands.
See an explained solution
export LC_ALL=C
printf 'device_id\tport\tvlan\n'
awk -F '\t' 'NR>1 {n=split($3,t,",");for(i=1;i<=n;i++){m=split(t[i],r,"-");lo=r[1]+0;hi=(m==1?lo:r[2]+0);for(v=lo;v<=hi;v++){k=$1 SUBSEP $2 SUBSEP v;if(!(k in seen)){seen[k]=1;printf "%s\t%s\t%d\n",$1,$2,v}}}}' trunks.tsv | sort -t "$(printf '\t')" -k1,1 -k2,2 -k3,3n
The normal form removes spelling differences and duplicates while preserving interface identity. Explicit numeric ordering makes reports stable across both the browser Linux tools and macOS native sort.