Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 dec2004.tar

Listing 5 filter.sh

#!/bin/ksh

#***********************************************************
# Listing 5:
# File: filter.sh
#
# Description:
# This script applies filtering rules to data read from standard input.
#
# Author: John Spurgeon (john.p.spurgeon@intel.com)
#
#***********************************************************

if [ -z "$ENTRAP" ]
then
   $(dirname $0)/entrap
   exit 0
fi

FILTER_FILE=$1
FILTER_IN=$TEMP_DIR/filter$$.in
FILTER_OUT=$TEMP_DIR/filter$$.out

> $FILTER_IN
while read line
do
   echo $line >> $FILTER_IN
done

if [ -f $FILTER_FILE ]
then
   while read PATHNAME MATCHTYPE ATTRIBUTES
   do
      awk 'BEGIN {ORS=""} {
         if ((($1!=pathname)&&(matchtype=="exact"))|| \
           ((1!=index($1,pathname))&&(matchtype=="prefix")))  {
            print $0"\n"
            }
         else {
            if (index(attributes,"!")>0) {
            }
            else {
               print $1
               if (index(attributes,"*")>0) {
               }
               else {
               if (index(attributes,"i")<=0) {
                  print " "$2
               }
               else {
                  print " -"
               }
               if (index(attributes,"p")<=0) {
                  print " "$3
               }
               else {
                  print " -"
               }
               if (index(attributes,"l")<=0) {
                  print " "$4
               }
               else {
                  print " -"
               }
               if (index(attributes,"o")<=0) {
                  print " "$5
               }
               else {
                  print " -"
               }
               if (index(attributes,"g")<=0) {
                  print " "$6
               }
               else {
                  print " -"
               }
               if (index(attributes,"s")<=0) {
                  print " "$7
               }
               else {
                  print " -"
               }
               if (index(attributes,"m")<=0) {
               print " "$8
               }
               else {
               print " -"
               }
               if (index(attributes,"1")<=0) {
               print " "$9
               }
               else {
               print " -"
               }
               if (index(attributes,"2")<=0) {
               print " "$10
               }
               else {
               print " -"
               }
               if (index(attributes,"3")<=0) {
               print " "$11
               }
               else {
               print " -"
               }
               if (index(attributes,"4")<=0) {
               print " "$12
               }
               else {
               print " -"
               }
               print "\n"
            }
      }
  }
}' pathname=$PATHNAME matchtype="$MATCHTYPE" attributes="$ATTRIBUTES" \
   < $FILTER_IN > $FILTER_OUT
   mv $FILTER_OUT $FILTER_IN
   done < $FILTER_FILE
fi

cat $FILTER_IN
rm $FILTER_IN


#!/bin/ksh