#!/usr/bin/bash ################################################################################### # Script name: cl # # This shell script scan .lst or .out files for proc compare results # # example: # > cl # - No parameter will scan all .lst files in current directory # > cl t_demog.lst # > cl *.lst # > cl t_*.lst # > cl -f alllsts.txt # -f flag to provide list of lst files in file # -h flag to display help # # Author: Sarwan Singh ################################################################################### ext=lst # check for argument value if [ "$1" = "-h" ] || [ "$1" = "" ]; then echo -e "\n\nExample:\n>cl t_demog.lst" echo ">cl *.lst" echo ">cl \$myprog (list of program names without .sas)" echo ">cl t_*.lst" echo ">cl -f alllsts.txt" echo " -f flag to provide list of lst files in file" echo " -h flag to display help" exit 0; elif [ "$1" = "-f" ]; then if [ "$2" = "" ]; then echo "\nERROR: Specify a filename with list of lst files after -f." echo "For help use: cl -h" echo "Exiting script.\n" exit 0; else #stop if infile does not exit if [ ! -e $infile ]; then echo "\nERROR: '$infile' does not exist." echo "Exiting script.\n" exit 0; else allfiles=`more $infile` fi fi elif [ "$1" = "" ]; then allfiles=`ls -al *.$ext | grep ^- | awk '{print $9}'` else allfiles=$* fi ### Find longest filename for printng format maxlen=0; for file in ${allfiles[@]} do filelen=`echo ${#file}` if [ ${maxlen} -lt ${filelen} ]; then maxlen=$filelen fi done ### check lsts for file in ${allfiles[@]} do ext=${file##*.} if [ $file == $ext ]; then if [[ "$file" == "v_o_"* ]]; then ext=out else ext=lst fi file=$file.$ext fi printf "Checking: ${file}" filelen=`echo ${#file}` perl -e "print '.' x ($maxlen+5-$filelen);" if [ ! -e $file ]; then printf ":'$file' does not exist.\n" elif [ -d $file ]; then printf ":'$file' is directory.\n" elif [ -f $file ]; then checkfl=`checklst ${file}` if [ "$checkfl" = "" ]; then printf ":PASS\n" else printf ":FAILED******\n" fi fi done