#!/bin/ksh # Script name: fil_len_each # # Where: in $FEDIR/scripts where FEDIR = /apps/nns_com/fea # # Purpose: Reads a file and shows the length of each line # ... with a pause every 100 lines. # # Written by: Blaise Montandon 4Oct96 # Updated by: Blaise Montandon 4Oct96 # while true while : do . $FEDIR/scripts/clearnns echo "\ ........................................................................... Show Line Lengths for each line 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 ENDLINE="" while test "$ENDLINE" = "" do echo " ........................................................................ Enter a range of lines (e.g. 20 100) (null to exit) ==> \c" read STARTLINE ENDLINE NNS_JUNK if test "$STARTLINE" = "" then break fi done # set -x nawk -v STARTLINE=$STARTLINE -v ENDLINE=$ENDLINE 'BEGIN { NUMLINS = 0; TOTCHAR = 0; MAXLEN = 0; MINLEN = 64000000; printf ("\n\n"); printf ("Line# Length\n"); printf ("-------- --------\n"); } { if (NR < STARTLINE) continue; if (NR > ENDLINE) exit; if ( length < MINLEN ) { MINLEN = length }; if ( length > MAXLEN ) { MAXLEN = length }; NUMLINS += 1 TOTCHAR += length($0) LINLEN = length($0) printf ("%8d %8d \n", NR , LINLEN); } END { print "....................................................................."; # print "\n"; # printf ("MAX/MIN line lengths OF THE RECORDS READ (#%d to #%d)", STARTLINE, ENDLINE); # print " "; # printf ("in 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 Read = %s", NUMLINS); CHARPERREC = TOTCHAR / NUMLINS print "\n"; printf ("Ave. Chars per Recs Read = %s", CHARPERREC); print "\n"; }' $FILEIN # set - echo " *** Press Enter to continue." read NNS_JUNK done