Couple of notes. “asorti” is not POSIX, so I would avoid that, however
implementing your own sort is painful as well. Something I learned with AWK is
you have to use the right tool for the job. So when you reach those cases when
you are breaking POSIX, it might be better to use Perl, Lua or Tcl instead. Also
when your “one liners” get that big, I find it helpful to just write it as a
proper script:
BEGIN {
while ("lsof -Pn -i" | getline) {
if (index($0, "LISTEN")) {
split($9, a1, /:/)
a2[a1[2]] = 1
}
}
n1 = asorti(a2, a3, "@ind_num_asc")
for (n2 = 1; n2 <= n1; n2++) {
print a3[n2]
}
}
Couple of notes. “asorti” is not POSIX, so I would avoid that, however implementing your own sort is painful as well. Something I learned with AWK is you have to use the right tool for the job. So when you reach those cases when you are breaking POSIX, it might be better to use Perl, Lua or Tcl instead. Also when your “one liners” get that big, I find it helpful to just write it as a proper script:
+1 on the awk tag