#!/bin/bash
#                       /usr/local/bin/funcs/parse
# https://crystalfaeries.net/posix/bin/funcs/parse
# celeste:crystalfaery PARSE Thu Apr 12 10:20:44 HST 2018
# not the originator of this code, merely sharing it;
# author unknown, license unknown.

function parse.(){ # auto complete helper, second argument is a grep against the function list     
    if [[ '' == "$@" ]]
    then
        echo "Parse Namespaced Functions List"
        cat $BASH_SOURCE | grep "^function[^(]" | awk '{j=" USAGE:"; for (i=5; i<=NF; i++) j=j" "$i; print $2" "j}'
    else
        echo "Parse Functions Matching: $@"
        cat $BASH_SOURCE | grep "^function[^(]" | awk '{j=" USAGE:"; for (i=5; i<=NF; i++) j=j" "$i; print $2" "j}' | grep $@
    fi
}
 
function parse.access_log_top_ten_code() { # Show the top ten code from access_log: useage ...code $FILE $CODE
    FILE=$1
    CODE=$2
    echo "Count the top ten $CODE'd pages"
 
    cat $FILE | awk '{ i=($9=="$CODE" ) ? $7 : ""; print i; }' | sort | uniq -c | sort -n | tail -n 11 | head -n 10
}
