#!/bin/ksh ################################################################################ # Print all stanzas of file # Assumes blank like is stanza seperator # Hardcodes comment character # # Written by Matt Baker mbaker@computeranddata.com ################################################################################ DEBUG=0 #VERBOSE=0 COMMENTCHAR="*" SEPERATORCHAR=":" OUTSEPERATORCHAR="," usage () { print "Usage error" print "$0 [-debug] [-c x] [-s y] [-o z] filename" #print "$0 [-v] [-debug] [-c x] [-s y] [-o z] filename" print "" print " -c comment char default: $COMMENTCHAR" print " -s seperator char default: $SEPERATORCHAR" print " -o output seperator char default: $OUTSEPERATORCHAR" print "" print "You may have to backslash metacharacters for options." print "i.e -c \#" print "" exit 1 } if (( ! $# )) then print "Usage: must provide an argument." exit 1 fi while (( $# )) do case "$1" in -debug) shift DEBUG=1 set -x ;; # -v) # shift # VERBOSE=1 # ;; -c) shift COMMENTCHAR=$1 shift ;; -s) shift SEPERATORCHAR=$1 shift ;; -o) shift OUTSEPERATORCHAR=$1 shift ;; *) FILE=$1 shift if [[ ! -f $FILE ]] then print "ERROR:3:File $FILE not found" exit 3 fi ;; esac done cat $FILE | grep -v ^$COMMENTCHAR \ | sed -e 's/ / /g' \ | awk '/\*${SEPERATORCHAR}/,/^$/ {if ( $0 !~ "^$" ) {printf "%s'$OUTSEPERATORCHAR'", $0} else {printf "\n"} } END { print "" }' \ | grep -v ^$