#!/bin/ksh # Script name: fil_len_summ # # Where: in $FEDIR/scripts where FEDIR = /apps/nns_com/fea # # Purpose: Reads a file and shows the minimum length and maximum length # records at end-of-file. # # Written by: Blaise Montandon 4Oct96 # Updated by: Blaise Montandon 4Oct96 # while true while : do . $FEDIR/scripts/clearnns echo "\ ........................................................................... Show Max/Min Line Lengths in a File: `hostname` At the following prompt for filename, enter a file name. (NOTE: You can switch to a different directory.) Examples: beam_test.fil or /local/scratch/${USER}/ideas/beam_test.fil " . $FEDIR/scripts/set_filnam if test "${filename1}" = "" then break # exit fi FILEIN=$filename1 if test "$filename1" != "" then FIRSTCHAR=`echo $filename1 | cut -c1-1` if test ! "${FIRSTCHAR}" = "/" then FILEIN=`pwd`/$filename1 fi fi FILETYPE=`file $FILEIN` if test "`echo "$FILETYPE" |grep 'text'`" = "" then echo " $FILEIN is not a text file. FileType is: $FILETYPE Exiting. If you think this file type should be supported by this 'rec-length' utility, please call an 'sgia' network Applications Support person in E40/C61, 0-2301. *** Press enter to continue." read NNS_JUNK # break continue fi echo " ........................................................................... Reading file ... Please wait ... " # set -x awk 'BEGIN { MAXLEN = 0; MINLEN = 64000000; } { if ( length < MINLEN ) { MINLEN = length }; if ( length > MAXLEN ) { MAXLEN = length }; } END { print "....................................................................."; print "\n"; printf ("MAX/MIN LINE LENGTHS for File: %s", FILENAME); print "\n"; printf ("Max Record Length (bytes) = %s", MAXLEN); print "\n"; printf ("Min Record Length (bytes) = %s", MINLEN); print "\n"; printf ("Number of Records = %s", NR); print "\n"; }' $FILEIN # set - # set -x NUMCHARS=`cat $FILEIN | wc -c` NUMLINES=`cat $FILEIN | wc -l` CHARPERLIN=`expr ${NUMCHARS} / ${NUMLINES}` # set - echo "\ Ave. Bytes per Record = $CHARPERLIN *** Press Enter to continue." read NNS_JUNK done