I would try a combo of grep, tail and head. If you have a file like Chris Mark Markus Marko Donna Jim
So if you are looking for the 2 and 3 occurrence of Ma in the file you would do this doing 'grep Ma test.txt | head -3 | tail -2' would return Markus and Marko. Where 3 is the Max number you want to start with and 2 is the number of occurrences you would like. Mark -----Original Message----- From: David Cantrell [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 01, 2002 9:05 AM To: Palit, Nilanjan Cc: [EMAIL PROTECTED] Subject: Re: [Boston.pm] grep w/ 'context' On Tue, Apr 30, 2002 at 03:40:20PM -0700, Palit, Nilanjan wrote: > This is really a unix question, but I thought I'll ask it here, in case > there is a perl tool to do the same: > > Is there an (easy) way of doing a grep with a 'context', i.e. grep will > provide the previous N & next M lines for every line that matches the > pattern (where N & M are arguments to the command)? No. You could lash something up by making grep spew out line numbers and then feeding them to awk. -- David Cantrell | Degenerate | http://www.cantrell.org.uk/david With ... the fact that Linux has become so easy to install that certain species of bacteria are now being hired by MIS departments, what was once the domain of rigorously trained, highly specialized professionals has devolved into the Dark Land of the Monkeys. -- Greg Knauss
