(97-04-02) HELP.AWK - Extract help information from AWK scripts

One shortfall of using AWK scripts for quick utilities is that they cannot support the -? command line switch. My solution to this is to build my AWK scripts based on a common template which contains easily extractable help information.

This script provides the extraction. It is designed to provide the same types of help which I provide in my 'C' utilities, and can extract the help from a set of AWK scripts. This means you can use it either to get information about running this particular script, or for getting a list of all the scripts in this directory.

#File: help.awk #?? HELP.AWK - Extract the help information from AWK scripts # #?v Written 97-04-02 #?v By Rob Ewan # # This is an AWK program to extract 'help' from other AWK scripts # #? Usage: #? AWK HELP file(s) #? Options: #? id=c To specify the type of help (follows -? options) #? # Put initialization code here BEGIN { id = " "; } # Now put the active code. pattern { action } # New file FILENAME != lastFile { # If it's not the first file, if ( lastFile != "" ) { # If not a summary, output a blank line to separate the listing if ( id != "?" ) print ""; } lastFile = FILENAME; } # Script ID: Simply dump it to the output /^#\?\?/ { # If not a help summary, output the script ID if ( id != "?" ) print } # Script help: Filter it for the type /^#\?/ { type = substr($0, 3, 1) if ( type == id ) { print } } # Put the closing code here END { }
- Read the book on AWK.
- Read more of my ideas on programming.
- Look up some other scripts.
- Go back to the front gate.

Do you have a script which I might find useful? Did you find a problem in one of my scripts? Write to Rob to let me know.
Page maintained by Rob.