Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

matching last line of a gzipped file

Status
Not open for further replies.

azzazzello

Technical User
Jan 25, 2005
297
US
Greetings!

I have the following problem. A program I run generated a data file. That data file is very large. It gets gzipped on the fly. Gzipped it could be several gigabytes large. If the data file is completed, it has the word DONE as the last line. This is variable - I can print out anything I want there. Otherwise, the datafile is truncated and deemed "bad". So here I am face-to-face with this file. I need to check for a particular pattern in the last line. However, the fastest way I can think of of doing it is zcat $file | tail -1. Zcat will take 30 seconds for a 1GB file on this machine. Is there another way of doing it? I cannot touch done files or something of the sort. Basically have to quickly extract if the last line of a gzipped file is a pattern I am looking for.
 
Well, there's no way around it, if the file has been gzipped, you need to uncompress it to see what's on that last line. I would use "[tt]gzcat[/tt]" instead of "[tt]zcat[/tt]" though.
Code:
gzcat $FILE | tail -1


 
You should look into changing the process that is gzipping the file in the first place. It should test the last line to see if it's "DONE" before gzipping it. You shouldn't waste processing time with a file that's incomplete.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top