## ## 'awk' PROGRAM NAME: diruse_files_all_levs_agesort_awkprog ## ## in $FEDIR/scripts ## where FEDIR=/apps/nns_com/fea ## ######################################################################## ## PURPOSE: ## ## This awk script is called by ## ## $FEDIR/scripts/diruse_files_all_levs_agesort_bygui ## ## to help reformat output from a 'file_ls_stat_info' script. ## ## 1) This 'awk' script is mainly used to replace the 3-char-alpha-month ## --- in output from 'file_ls_stat_info' --- by a 2-char-numeric-month. ## ## 2) It also converts file-size in BYTES to file-size in MEGA-BYTES. ## ######################################################################## ## INPUT: ## The output from 'file_ls_stat_info' looks like ## ## 41688 -rw-r--r-- bmo01 user 2003 Mar 10 16:13:14 ## ## in other words, ## ## ## and the field numbers are ## 1 2 3 4 5 6 7 8 9 ## ######################################################################## ## OUTPUT: ## The output from 'file_ls_stat_info', for the above example input, ## looks like ## ## 41688 -rw-r--r-- bmo01 user 2003 03 10 16:13:14 ## ######################################################################## ## MORE INFO: ## See comments in the calling script ## 'diruse_files_all_levs_agesort_bygui'. ## and in 'file_ls_stat_info'. ######################################################################## ## FOR TESTING: Can paste the following at a shell-command prompt: ## ## echo "41688 -rw-r--r-- bmo01 user 2003 Mar 10 16:13:14 " | ## awk -f /apps/nns_com/fea/scripts/diruse_files_all_levs_agesort_awkprog_NEW ######################################################################## ## THIS 'awk' PROGRAM IS ## CALLED BY: $FEDIR/scripts/diruse_files_all_levs_agesort_bygui ## ## which is called by the ## 'spacetools' script in $FEDIR/scripts ## actually, by spacetools.chestdef in $FEDIR/scripts ######################################################################## ## MAINTENANCE HISTORY: ## Written by: B.Montandon O06 21Sep2000 Based on ## 'simtec_generic2Dels_2stl_awkprog' ## in $FEDIR/scripts and ## p.290 of 'Unix Power Tools'. ## ## Updated by: Blaise Montandon 28apr2003 Revised this awk script to ## handle output from script ## 'file_ls_stat_info', instead of ## output from 'ls -l'. ## ## Updated by: Blaise Montandon 28apr2003 In the 'awk' command, ## replaced the '$9' field by a ## 'COLfilnam = index($0,$9)' technique ## --- to return complete filenames when ## there are embedded blanks in the name. ######################################################################## BEGIN { ########################################################################## ## START OF awk-BEGIN-section: (not used currently; kept as a sample) ########################################################################## # printf ("............... %-65s\n",VAR_IN) # i=0 # ## i is a rec counter. } { ########################################################################## ## START OF awk-BODY (main-section) ########################################################################## ## SAMPLE 'file_ls_stat_info' INPUT OF THE TWO DATE-TIME-STAMP TYPES: ## ## ## 41688 -rw-r--r-- bmo01 user 2003 Mar 10 16:13:14 ## ## Field numbers: ## 1 2 3 4 5 6 7 8 9 ## ########################################################################## ## ## For age-sorting, this 'awk' script is used to reformat MONTH info ## from 'file_ls_stat_info', like ## ## 2003 Mar 10 ## to ## 2003 03 10 ## ## Then an external 'sort' sorts on the yr-mo-dy-time data in ## output columns 5,6,7,8. ########################################################################## if ($6=="Jan") {MONUM="01" } else { if ($6=="Feb") {MONUM="02" } else { if ($6=="Mar") {MONUM="03" } else { if ($6=="Apr") {MONUM="04" } else { if ($6=="May") {MONUM="05" } else { if ($6=="Jun") {MONUM="06" } else { if ($6=="Jul") {MONUM="07" } else { if ($6=="Aug") {MONUM="08" } else { if ($6=="Sep") {MONUM="09" } else { if ($6=="Oct") {MONUM="10" } else { if ($6=="Nov") {MONUM="11" } else { if ($6=="Dec") {MONUM="12" } else {MONUM="??"} } } } } } } } } } } } ########################################################################## ## RE-FORMAT THE MONTH FIELD (field 6), and ## THE FILE-SIZE FIELDS (field 1). ########################################################################## ## The output from 'file_ls_stat_info' looks like ## ## 41688 -rw-r--r-- bmo01 user 2003 Mar 10 16:13:14 ## 1 2 3 4 5 6 7 8 9 ########################################################################## ## NOTE on filenames with embedded spaces: ## ## To handle filenames with embedded spaces, we use 'substr($0,COLfilnam)' ## in awk, instead of '$9' --- where ## we set COLfilnam with the expression 'COLfilnam = index($0,$9)'. ## ## The 'substr($0,COLfilnam)' gets the substring of the record, $0, ## starting at column COLfilnam and going to the end of the record. ## ## This is not elegant, because when the contents of field $9 matches one ## of the fields, $1 thru $8, some extra chars before the filename may be ## printed. ## ## Have not been able to find an 'ideal' method to extract the filename ## with 'awk'. Would be nice if we could 'index' fields like $9 to get, ## with no exceptions, the column number of its starting character. ## ## This technique came from another files-report script: ## 'diruse_files_all_levs_fullnamesort_bygui'. ## ## See script 'diruse_files_onelevel_sizesort_bygui' for a more foolproof ## method using 'substr($0,COLmonth + 12)'. ######################################################################### # printf ("%13.6f %-10s %-8s %-8s %5s %2s %2s %5s %s\n", $1/1000000, $2, $3, $4, $5, MONUM, $7, $8, $9 ) COLfilnam = index($0,$9) printf ("%13.6f %-10s %-8s %-8s %5s %2s %2s %5s %s\n", $1/1000000, $2, $3, $4, $5, MONUM, $7, $8, substr($0,COLfilnam) ) } ## END OF awk-BODY (main-section) ########################################################################## ## START OF awk-END-section: (not used currently; kept as a template) ########################################################################## # END { # if ( i==0 ) # { # print "*ERROR: No recs were found in the input file --- output of 'ls -l'." # } # printf ("Number of files listed = %12d \n",i) # } ## END OF awk-program