Skip to content

Instantly share code, notes, and snippets.

@dinoocch
Created December 4, 2015 07:32
Show Gist options
  • Save dinoocch/568bebdd080c9d41a4f7 to your computer and use it in GitHub Desktop.
Save dinoocch/568bebdd080c9d41a4f7 to your computer and use it in GitHub Desktop.
cat who.out | gawk 'function repeat(str,n,rep,i){for( ; i<n; i++){rep = rep str}; return rep} BEGIN {RS = "" ; FS = "\n"} {split($1, a, " | "); cname = a[1]; d[NR] = cname; for (i = 2; i <= NF; i++) {split($i, b, " "); c[cname][b[1]]++}} END {asort(d);maxC = 0; maxU = 0; for (cname in c) { if (length(cname) > maxC){maxC = length(cname);} for (user in c[cname]){if (length(user) > maxU){maxU = length(user)}}}; maxU += 3; maxC +=3; print repeat("-", maxC) "|" repeat("-", maxU); for(ci in d){cname = d[ci]; users = ""; current = 1; for (user in c[cname]){if(user != "cv"){users = users user; if(current < length(c[cname])){ users = users "\n" repeat(" ", maxC) "|" }}}; print cname repeat(" ", maxC-length(cname)) "|" users; print repeat("-", maxC) "|" repeat("-", maxU)}}' | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment