#!/bin/awk -f

BEGIN {
  print "\nName of command and number of command line options:\n"

  gnu = "cat tac nl od base64"
  gnu = gnu " fmt pr fold"
  gnu = gnu " head tail split csplit"
  gnu = gnu " wc sum cksum md5sum sha1sum"
  gnu = gnu " sort uniq comm ptx tsort"
  gnu = gnu " cut paste join"
  gnu = gnu " tr expand unexpand"
  gnu = gnu " ls dir vdir dircolors"
  gnu = gnu " cp dd install mv rm shred"
  gnu = gnu " mkdir rmdir unlink mkfifo mknod ln link readlink"
  gnu - gnu " chgrp chmod chown touch"
  gnu = gnu " df du stat sync"
  gnu = gnu " yes"
  gnu = gnu " expr"
  gnu = gnu " tee"
  gnu = gnu " dirname basename pathchk"
  gnu = gnu " stty printenv tty"
  gnu = gnu " id logname whoami groups users who"
  gnu = gnu " date uname hostid"
  gnu = gnu " chcon runcon"
  gnu = gnu " env nice nohup su"
  gnu = gnu " sleep"
  gnu = gnu " factor seq"
   
  max = split (gnu,commands," ")
   
  for (i = 1; i <= max; i++) {
    options = 0;
    cmd = commands[i] " --help"
    while ((cmd | getline) > 0) {
      if ($0 ~ /^Usage:/) name = $2;
      if ($0 ~ /^ +-/) options++
    }
    close(cmd);
    print name ": " options;
    total = total + options;
  }
  print "\nNumber of commands: " max "\n"
  print "Total number of options: " total
  print "  without counting --version and --help: " total - (max * 2) "\n"
  print "Average per command: " total / max
  print "  without counting --version and --help: " (total / max) - 2 "\n"
}

