in reply to Searching a gzip file

How would your approach work with a normal file?

If you show us the code you have already, then we can likely help you much better on how to approach moving from a normal file to a compressed file. Have you considered just decompressing your compressed file?

Personally, I'm fond of just using the pipe-open like this:

my $file = 'some_file.gz'; open my $fh, "gzip -cd $file |" or die "Couldn't read/decompress '$file': $!"; while (<$fh>) { ... };

This approach also lends itself well to using the flip-flop operator .., see perlop.

Replies are listed 'Best First'.
Re^2: Searching a gzip file
by baski (Novice) on Aug 26, 2010 at 08:16 UTC
    open FILE, '>log_'.$expt_name.'.txt' or die "Can't open file : $!\n"; print FILE "***********************\n"; my @Ids=`zcat $log_files | sed -e 's/\\\n/\\n/g' | grep -B5 'name\?'| + grep Id`; foreach (@Ids){ print $_."\n"; #Search and print the first occurence of <score> after $_ } close FILE;

    There is not much code I have written so far :), trying to figure out which tools to use..thanks

      While I'm not sure why you seem to write a shell script in Perl instead of using the Perl built-in mechanisms, I think if you post about 10 relevant lines of your input data. Your current approach should work regardless of whether the file is compressed or not, so I'm not sure I've understood where you see your problem.