# Assume that our input is a list of page/visitor pairs. # Also, assume that the input is sorted by page. What we wish # to do is to print the name of the visited page once, and # then list all the vistors out on separate lines following # the page name. { # Do we have a new page yet? if ($1 != current_page) { # Yep, new page. List out all the visitors for the old # current_page. print_visitors(); # Reset the list of visitors and continue. num_visitors = 0; delete visitors; printf "%s\n", $1; current_page = $1; } } { # Record this visit. visitors[num_visitors] = $2 num_visitors++; } END { # Be sure to list the visitors for the last page, too. print_visitors(); } function print_visitors () { # We want to print each visitor only once. for (v in visitors) { if (!printed[visitors[v]]) { printf "\t\t%s\n", visitors[v]; printed[visitors[v]] = 1; } } delete printed }