Shell Programming Case Study #2
#!/bin/sh
# case study #2
# LIST is a file that contains a list of filenames.
# I want to see which of those files exist and which do not
# in the directory LONGPREFIX.
CLASS=242
LIST=/cgi-bin/s2004fal/hmwk/qfiles.$CLASS
SHORTPREFIX=f.hmwk/pracun/
LONGPREFIX=/cgi-bin/s2004fal/hmwk/$SHORTPREFIX
STATUS=1 # assume a non-successful result
T1=/tmp/f1.$$
T2=/tmp/f2.$$
rmtmp() {
rm -f $T1 $T2 # -f suppress err msg if file does not exist
exit $STATUS # exit script with meaningful Status code
}
trap "rmtmp" 0 1 2 3 15
sort $LIST > $T1
ls $LONGPREFIX |
grep -v notincluded |
sed "s;^;$SHORTPREFIX;" |
sort > $T2
# must use dbl quotes, not single, in sed to allow $SHORTPREFIX
# must change sed delimiter since $SHORTPREFIX contains slashes
read XX
comm $T1 $T2
STATUS=$?
f.hmwk/pracun/pracun13.poor
f.hmwk/pracun/pracun14.chk
f.hmwk/pracun/pracun14.cmds
f.hmwk/pracun/pracun14.cmds2
f.hmwk/pracun/pracun14.umask
f.hmwk/pracun/pracun18.re1
f.hmwk/pracun/pracun18.re2
f.hmwk/pracun/pracun18.tel
f.hmwk/pracun/pracun18.tel2
f.hmwk/pracun/pracun19.sed
f.hmwk/pracun/pracun19.sed-2
f.hmwk/pracun/pracun19.sed-3
col1 = files in LIST that are not in DIR
col2=files in DIR that are not in LIST
col3=files in common