Grep pattern file - filter duplicate hits on patterns -


i have pattern file use grep going through logs, since patterns appear on multiple places in logs, long output. want 1 line each of patterns pattern file.

for example,

patternfile

aaa bbb ccc 

logfile

12 aaa 23 bbb 45 bbb 67 ddd 89 bbb 

so grep -f patternfile logfile, i'd

12 aaa 23 bbb 45 bbb 89 bbb 

but want

12 aaa 23 bbb 

not sure how pipe this. thanks

here perl program want:

pgrep.pl [patternfile] [ logfile ]

caveat patternfile doesn't have wildcards

pgrep.pl ---

#/usr/bin/perl  use strict;  sub usage {     print "usage: $0  [patternfile]  [logfile ]\n";     exit; }  sub load {    $file = shift;    open $input, "<", $file or die "unable open $file : $!";    @data=<$input>;    close $input;    foreach ( @data )    {        chomp;        s/\cm//g;        s/^\s+//;        s/\s+$//;    }     return @data; } $patternfile = shift or &usage();  @patterns = &load( $patternfile );  $logfile = shift or usage();  @data = &load( $logfile );  foreach $p ( @patterns ) {     next if not length $p;     ($found ) = grep {/$p/} @data;     print $found,"\n" if $found; } 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -