grep for a few lines

September 15th, 2006 mysurface Posted in grep, Text Manipulation | Hits: 6983 | No Comments »

One of the useful option for grep, when you find the keyword you are searching, instead of return a particular line that contains the keyword, it allows you to specified how many lines to return by specified -A option.

Let say I want to return 5 lines when i found “main” at hello.c.

grep -A 5 main hello.c

Leave a Reply