#!/bin/sh #set -vx # Amber saved test updater # Scott Brozell, TSRI dif_extension=.dif save_extension=.save # create usage statement usage() { cat << EOF Usage: $0 [-v] regular_expression Description Search *$dif_extension files for regular_expression and make the corresponding output files the $save_extension files. Options -v verbose. EOF exit 1; } # process command line options # note that getopt fails by losing the quotes of quoted regular expressions on='on' verbose='' if [ "$1" = '-v' ] then verbose=$on shift fi # command requires 1 argument if [ $# -lt 1 ] then usage; fi # loop over dif files for dif in `find . -name "*$dif_extension" ! -size 0c -print` do if [ "$verbose" = "$on" ]; then echo "Searching $dif" fi if grep "$1" $dif then if [ "$verbose" = "$on" ]; then echo " match found; printing $dif:" cat $dif fi directory=`dirname $dif` base=`basename $dif $dif_extension` echo "move $base to $base$save_extension ?" read answer if [ "$answer" = "yes" -o "$answer" = "y" -o "$answer" = "Y" -o "$answer" = "Yes" ] then mv $directory/$base $directory/$base$save_extension if [ $? -eq 0 ] then echo "Move successful" echo else echo "Move Failed !" echo fi fi else if [ "$verbose" = "$on" ]; then echo " No match." fi fi done exit