Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-29-2010, 04:41 AM   #1
Registered: Sep 2009
Posts: 55

Rep: Reputation: 0
grep ??? searching a file and outputting 5 lines either side...


Anyone tell me how I can search a file and output the following.

1 - 10 lines with the search result in the middle
2 - line numbers (if possible?)

I have the grep working, simple search for a string but I would like to output the above 5 lines and the following 5 lines. Any thoughts?
Old 09-29-2010, 04:42 AM   #2
Registered: Sep 2009
Posts: 55

Original Poster
Rep: Reputation: 0

-A for trailing lines
-B for leading lines
-n for Line numbers

EDIT - I have solved this myself - forgive me

Last edited by redhatuser1; 09-29-2010 at 04:44 AM.
Old 09-29-2010, 04:45 AM   #3
Senior Member
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,145
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
:set nu
This is for vi editor


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
searching pattern in tab delimited file using grep vaibhavs17 Programming 5 03-05-2010 02:02 AM
Searching using grep gregarion Programming 10 01-14-2010 10:10 AM
Using CAT / GREP to remove a set of lines from a file wesgarner Linux - Newbie 13 11-14-2009 11:41 AM
script to grep lines out of a file qipman Linux - General 5 09-26-2007 01:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:38 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration