in reply to Search in the .tgz file without unpack and untar
(You might need an extra option, "--binary-files=text" on the grep command, depending on which version of grep you have.)gunzip -c *.tgz | grep target_regex > target.hits
Or else I'd write a perl script like this:
(And in the latter case, I'd probably use @ARGV to set the path for where to find the tgz files, what regex to apply, and/or whether to read the list of tgz file names from STDIN, so that the script serves a general range of uses.)#!/usr/bin/perl use strict; use PerlIO:gzip; for my $file (<*.tgz>) { open( T, "<:gzip", $file ) or do { warn "open failed on $file: $!\n"; next; }; while (<T>) { print if /target_regex/; } }
|
|---|