Listing 3: cdiff.sh
:
#######################################################
# cdiff.sh - show changes using diff
#######################################################
# This is an fchange.sh support program. fchange.sh
# uses this program to diff the last two entries in the
# track file.
# filename is passed on command-line
test -f "$1" || exit 1
# cleanup first
rm -f tag_?
awk 'BEGIN { y=0; depth=2; }
/^#_change: / {
y++
if ( y == 2 )
y=0
newtag=sprintf("tag_%d", y)
count[newtag]=1
}
{
line[newtag count[newtag]]=$0
count[newtag]++
}
END {
for (m=0; m < depth; m++) {
newtag=sprintf("tag_%d", m)
print "" > newtag
for (i=1; i < count[newtag]; i++)
printf("%s\n", line[newtag i]) >> newtag
close(newtag)
}
}' $1
# now diff the two files
diff tag_?
|