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 11 count_changed.sh

#!/bin/ksh

#*********************************************************************
# Listing 11:
# File: count_changed.sh
#
# Description:
#
# This script takes a file generated by the compare command, and 
# counts the number of files that were changed. 
#
# A file is changed if its pathname appears in both the rhs 
# and lhs files when the comparison is made. If a file is
# changed, the comparison file contains two lines beginning
# with either a > or a < character and containing the file's pathname
# in field 2.
#
# Author: John Spurgeon (john.p.spurgeon@intel.com)
#
#*********************************************************************

if [ "$#" -ne 1 ]
then
   echo "[$(basename $0)] Usage: $(basename $0) filename"
   exit 0
fi

# FILE is the name of a file generated by a previous comparison.
# The format must be consistent with the output produced by the compare command
FILE=$1

if ! [ -f $FILE ]
then
   echo "[$(basename $0)] Error: $FILE does not exist!" >& 2
   exit 1
fi

# Count the total number of lines in the file.
TOTAL=$(wc -l < $FILE)

# Count the number of unique file names.
UNIQUE=$(awk '{print $2}' $FILE | sort -u | wc -l | awk '{print $1}')

# Calculate the number of filenames that appeared in both the rhs and lhs files.
# This is the number of files that were "changed".
echo $((TOTAL - UNIQUE))


#!/bin/ksh