The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-06-2008
dayscripter dayscripter is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
How to read/process a .gz file, one line at a time?

Hello

I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions.

I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep ${ERROR}" because I would have to parse every single large log file for each of the known errors and the time to do that would be days. So I want to parse the log files only once, read each line, compare the error, and increment the error count for each error. I know how to do most of this except the part about processing one line at a time from a .gz file.

I came up with something like this but it's not working. It's outputing all the lines in the file, instead:

Code:
 
while read file_line
do
ERROR=`grep ^ERROR ${file_line}`
print ${ERROR}
done < `gzcat 080803.gz`
This is the output that's coming out. It should output only the lines beginning with ERROR but it's showing everything such as the AUDIT lines. I want just the ERROR lines. And there is no carriage return.

AUDIT ; WebContainer : 2008-08-04 00:11:51,554 ; com.at.commons:A_EndRequest - Done preparing response for transaction for uri '/docroot/common' in 337 ms.^JAUDIT ; WebContainer : 2008-08-04 00:11:58,885 ; com.at.commons:A_BeginRequest - Received request for transaction for uri '/docroot/common'.^JAUDIT ; WebContainer : 20-08-08-04 00:11:59,136 ; com.at.commons:A_EndRequest - Done preparing response for transaction for uri '/docroot/common' in 251ms.^JAUDIT ; WebContainer : 2008-08-04 00:12:08,686 ; com.at.commons:A_BeginRequest - Received request for transaction for uri '/docroot/common'.^JAUDIT ; WebContainer : 2008-08-04 00:12:09,078 ; com.at.commons:A_EndRequest - Done preparing response for transaction for uri '/docroot/common' in 392 ms.: cannot open

I wanted the output to look like this instead:

ERROR ; WebContainer : 2008-08-03 04:33:45,787 ; com.models.userlist.query:E_AggregationError
ERROR ; WebContainer : 2008-08-03 04:33:59,930 ; com.models.userlist.query:E_AggregationError
ERROR ; WebContainer : 2008-08-03 04:34:31,751 ; com.app.cdmeng.combination:E_marshalException

What am I doing wrong? Any assistance would be much appreciated.

Thanks.