#!/bin/sh # LEFTIFY - first incarnation of "sweep" # Script searches through all filepro files for occurances of a field # type you specify, and performs a Left-Justify on that field in all # records of all files containing that field. # # Brian K. White - linut@squonk.net # -- # Brian K. White http://www.squonk.net/users/linut # +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. # filePro BBx Linux SCO Prosper/FACTS AutoCAD #callahans Satriani # YOU MUST EXAMINE THESE VARIABLES BEFORE RUNNING #SAVEKEY=`tput kf12` ;export SAVEKEY # F12 - save key (Albany Burner Control) SAVEKEY="\033\033" ;export SAVEKEY # Esc Esc - save key (default) INSLKEY=`tput kf3` ;export INSLKEY # F3 - insert line key ############################################################################## echo "Working in $PFDIR - Hit [Delete] to abort." echo "Text to search for in field names (case insensative)..." echo " - you can enter parts of descriptions, field sizes, or edit types" echo " - weeding is done in the order listed. The first INCLUDE gathers the" echo " possibilities, the the subsequent INCLUDES and EXCLUDES reduce the" echo " selection set." echo " - you can leave any entries blank. leaving all blank will result in" echo " selecting every field of every file." echo "" echo " - TEST's are harmless, but if you think you may have done ANY sort of" echo " typo while entering parameters for a real run, then just don't run" echo " it, hit Enter or Delete, but not R, unless you are sure." echo "" echo "Text (1 of 3) to INCLUDE a field :\c" ;read CO1 echo "Text (2 of 3) to INCLUDE a field :\c" ;read CO2 echo "Text (3 of 3) to INCLUDE a field :\c" ;read CO3 echo "Text (1 of 3) to EXCLUDE a field :\c" ;read NO1 echo "Text (2 of 3) to EXCLUDE a field :\c" ;read NO2 echo "Text (3 of 3) to EXCLUDE a field :\c" ;read NO3 echo "Enter R to RUN or any other key to TEST :\c" ;read R case $R in r|R) echo "Are you sure (y/n)?:\c" ;read S case $S in y|Y) R=1 ;; *) unset R ;; esac ;; *) unset R ;; esac LOG=$PFDIR/sweep_$CO1_`date +%b%d-%H%M` echo "SWEEP - `date +%c`">$LOG [ $R ] || echo "** TEST RUN - no data was actually modified **" >>$LOG echo "" >>$LOG echo " A LEFT-JUSTIFY was performed on the following fields in all records in" >>$LOG echo " the following files in $PFDIR/filepro" >>$LOG echo "" >>$LOG echo " The selection parameters were:" >>$LOG echo "" >>$LOG echo " INCLUDE $CO1" >>$LOG echo " INCLUDE $CO2" >>$LOG echo " INCLUDE $CO3" >>$LOG echo " EXCLUDE $NO1" >>$LOG echo " EXCLUDE $NO2" >>$LOG echo " EXCLUDE $NO3" >>$LOG echo "" >>$LOG echo "File \tField\tDefinition from map file" >>$LOG echo "------------------------------------------------------------------------------" >>$LOG [ "foo$CO1" = "foo" ] && CO1=: [ "foo$CO2" = "foo" ] && CO2=: [ "foo$CO3" = "foo" ] && CO3=: [ "foo$NO1" = "foo" ] && NO1=SwEeP [ "foo$NO2" = "foo" ] && NO2=SwEeP [ "foo$NO3" = "foo" ] && NO3=SwEeP unset DEBUG #DEBUG=1 PRC=SwEeP_LJ ABE=ASCII; export ABE PFME=OFF; export PFME # yes PFME affects dcabe. cd ${PFDIR}/filepro for PFNAME in `grep -i -l "$CO1" */map |sed "s/\/map//g" ` ;do cd ${PFNAME} ;export PFNAME # ;[ $DEBUG ] && pwd # ls prc.$PRC >/dev/null 2>&1 && exit 2 # ls out.$PRC >/dev/null 2>&1 && exit 2 for LINE in `grep -i -n "$CO1" map |grep -i "$CO2" |grep -i "$CO3" |grep -i -v "$NO1" |grep -i -v "$NO2" |grep -i -v "$NO3" |cut -d":" -f1 ` ;do FIELD=`expr $LINE - 1` echo "$PFNAME \tfield $FIELD" echo "$PFNAME \t$FIELD\t\c" >>$LOG grep -i -n "$CO1" map |grep -i "$CO2" |grep -i "$CO3" |grep -i -v "$NO1" |grep -i -v "$NO2" |grep -i -v "$NO3" |grep "^$LINE:" |sed "s/$LINE://" >>$LOG [ $R ] && { rm -f prc.$PRC ;rm out.$PRC >/dev/null 2>&1 ${PFDIR}/fp/ddir ${PFNAME} -l >/dev/null 2>&1 echo "3\r${PRC}\r\r\r$FIELD=\"\"{$FIELD${SAVEKEY}YNNX\c" | ${PFDIR}/fp/dcabe >/dev/null 2>&1 echo "\r${PRC}\r5${SAVEKEY}${SAVEKEY}${SAVEKEY}X\c" | ${PFDIR}/fp/dmoedef >/dev/null 2>&1 echo "${PRC}\r\r${SAVEKEY}Y\c" | ${PFDIR}/fp/dreport >/dev/null 2>&1 rm -f prc.$PRC ;rm out.$PRC >/dev/null 2>&1 $PFDIR/fp/dxmaint $PFNAME -ra -e >/dev/null 2>&1 } done cd .. done echo "" echo "------------------------------------------------------------------------------" >>$LOG echo "end of log" >>$LOG [ $R ] && { echo " LOG file was written to $LOG" echo " press Enter to continue...\c" ;read junk } || { less $LOG ;rm -f $LOG }