Code Files

parselog.awk

Generated on Tue Dec 05 17:39:06 Eastern Standard Time 2006 from parselog.awk


# Program      	: PARSELOG.AWK
# Purpose      	: Parse MTA and POA files to create
#                "MTAname, Datetime,  ..." or "POAname, Datetime, ..." on each output line
# Author       	: Bob Jonkman <bjonkman@sobac.com>

# Copyright 2008 Bob Jonkman and/or SOBAC Microcomputer Services

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Date         	: 12 November 2001
# Modified     	: 19 March 2002   - Changed output datetime format to "yyyy-mm-dd hh:mm:ss"
#               : 6 February 2006 - Changed index(srch) to match(srch) to allow regex 

# Usage        	: GAWK  -f parselog.awk -v PO=%PO% -v srch=%1 inputfile >> outputfile

# Parameters   	: PO   = POAname/MTAname to be specified on the command line
#                srch = Search String, specified on command line

# Input format 	: time (hh:mm:ss), threadno, message  
#                (Input Field Separator is a space, so the message will be split into fields as well)

# Output format	: POAname/MTAname, Datetime (yyyy-mm-dd hh:mm:ss), threadno, message (as one field)
#                (Output Field Separator is a comma)

# Requirements	: Input file has date encoded in log filename:
#                "---------- \\COTGW100\SYS\LOGFILES\1108POA.005"
#                indicates "8 November" (and the 5th log file for that date)

# Notes		: The pattern construct "index(srch)" was the only way I
#                found to be able to match patterns on a variable

# GAWK		: The Free Software Foundation's GAWK for Windows is available at
#			http://www.gnu.org/software/gawk/gawk.html

BEGIN {  OFS  = "," ;         # Output Field Separator
         BACKSLASH = "\\" ;
         QUOTE = "\"" ;

         year = strftime("%Y")  # Four digit year (log files do not provide year)
                                #   This is likely to break when reading old logs in January/February

         if ( PO == "" )     
           { PO="unknown" } ; # Force a name for PO if none is specified on the command line

#		    print( "===== DEBUG =====   srch = " srch "   PO = " PO);

      }   

FNR == 1    {   numfields = split(FILENAME,f,BACKSLASH) ;              # Parse for directories

#				print("===== DEBUG =====", FILENAME, numfields, f[numfields]) ;

                month = substr(f[numfields],1,2);             # extract the first two characters from FILENAME as the month
                day   = substr(f[numfields],3,2);             # extract the next two characters from FILENAME as the day
#               print("===== DEBUG =====", numfields, month, day, f[0], FILENAME);
}

match($0,srch)	{   print(PO, year "-" month "-" day " " $1, $2, QUOTE substr($0,14) QUOTE) ; # output a line (message begins at column 14)
                    unique++ ;
}

END     { #  print("=====") ;
          #  print(unique,"Unique") ;
}

# EOF: PARSELOG.AWK


   

1 files processed.