in reply to (jeffa) Re: linux grep feature
in thread Emulating GNU grep -A and -B switches with perl (was: linux grep feature)
Your code works great for simple cases, but fails for files that have matches that are close together. You end up with duplicate lines being displayed.
for example try the following:
grep.pl -A 1 -B 1 test datawith the file 'data' containing:
test 1 test 2 test 3
The results are:
test 1 test 2 test 1 test 2 test 3 test 2 test 3
Also your version will parse the entire file before printing out any results. This will be slow for large files.
Still a good base to start from though...
Cheers
Cees
|
|---|