LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
LinkBack Search this Thread
Old 09-29-2010, 03:41 AM   #1
redhatuser1
Member
 
Registered: Sep 2009
Posts: 55

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


Hi,

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, 03:42 AM   #2
redhatuser1
Member
 
Registered: Sep 2009
Posts: 55

Original Poster
Rep: Reputation: 0
Solution

-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 03:44 AM.
 
Old 09-29-2010, 03:45 AM   #3
prayag_pjs
Senior Member
 
Registered: Feb 2008
Location: Pune - India
Distribution: Fedora,RedHat,CentOS,Gentoo
Posts: 1,132
Blog Entries: 4

Rep: Reputation: 146Reputation: 146
Quote:
:set nu
This is for vi editor
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 11:17 AM.

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