#!/usr/bin/nawk -f # To run this script: # nawk -f inventory.nawk -v startup=./approved ./inv.txt BEGIN { # Pre-processing stuff USAGE="Usage: nawk -f inventory.nawk -v"\ " startup=./approved ./inv.txt\n" approved = unapproved = 0 FS="\"" if (!startup) { print "\nThe location of the startup control file was not passed" print "to this nawk script upon invocation, exiting!\n" USAGE DEEP = 6 ; exit 1 } if (getline < startup != 1) { close(startup) print "\nThe startup control file "startup" does not exist or is empty." print "Restore "startup" and rerun this program.\n" USAGE DEEP = 6 ; exit 1 } else { aparray[$2] } # Create the associative array while (getline < startup > 0) { aparray[$2] } # Create the associative array # You may want to comment the following two lines: # print "Here's the list of approved software\n" # for (idx in aparray) print idx FS="\t" } # Main program starts now, here's the meat of this code { if ($0 !~ /Query Name: Native software/ && $0 !~ /TME_OBJECT_LABEL\tPACKAGE_NAME\tPACKAGE_VERS\tFILE_PATH/) { if ($2 in aparray) { approved++; } # print " " $2 ": Matched!" } else { unapproved++; print "Computer: " $1 ": " $2 } } } END { # post-processing stuff if (DEEP == 6) exit 1 # Comment the following line if you don't want totals print "\nApproved programs: " approved ", Unapproved programs: " unapproved }