As I said in my comment, the command you posted works fine on my LMDE (pcregrep version 8.31 2012-07-06). However, since your regex only specifies part of the string you're looking for, you could also do this with normal grep
:
grep -A 6 'Found an' log_*.txt | grep -C 3 10019874
The -A 6
will print the line matching the string passed and the 6 following lines and the -C 3
will print the 3 surrounding lines. The end result is exactly the same as the pcregrep
approach you were using.
If your pattern can have differing numbers of lines, that can explain the segfault. Presumably, in some of your files, the matched section is too long and causes an out of memory error. One way around it would be a little scripting:
perl -ne '$c=1 if /Found an/; ## set $c to 1 if this line matches 'Found on'
if($c){ ## If $c is defined and non-0
push @F,$_; ## Add the current line to the @F array
$c++ if /10019874/; ## Increment $c if this line matches '10019874'
if(/Processed/){ ## If this line matches 'Processed'
print "@F" if $c>1; ## Print the contents of @F if $c is >1
@F=""; $c=0; ## Empty @F, set $c to 0.
}
}' log_*.txt
The same thing as a one liner:
perl -ne '$c=1 if /Found an/; if($c){push @F,$_; $c++ if /10019874/; if(/Processed/){print "@F" if $c>1; @F=""; $c=0;}}' log_*txt
pcregrep
are you using? What OS? – terdon Jun 19 '14 at 13:18