On Thu, Nov 16, 2000 at 07:10:57AM -0600, Eric Clover wrote:
> hello,
> i have a need for something that will cat a large file, grep it for a
> word and have the ability to pull the 5 lines before and after (more
> like 3 lines before and 8 lines after) the grep has found the word and
> display the results. example:

That's a case of RTFM... :-) (assuming you have grep 2.3 or higher
installed, which should be the case for RHL 6.2 and higher, IIRC)

>From the grep man page:
<quote>
     All variants of grep understand the following options:
     -A NUM, --after-context=NUM
          Print NUM lines  of  trailing  context  after  matching
          lines.
     -B NUM, --before-context=NUM
          Print NUM lines  of  leading  context  before  matching
          lines.
</quote>

So, in your case:

grep --before-context=3 --after-context=8 'EXPRESSION' FILE

(Note: No "cat" necessary...)

HTH,

Thomas
-- 
             "Look, Ma, no obsolete quotes and plain text only!"

     Thomas Ribbrock | http://www.bigfoot.com/~kaytan | ICQ#: 15839919
   "You have to live on the edge of reality - to make your dreams come true!"



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to