LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-16-2003, 10:21 AM   #1
cyph3r7
Member
 
Registered: Apr 2003
Location: Silicon Valley East, Northern Virginia
Distribution: FreeBSD,Debian, RH, ok well most of em...
Posts: 238

Rep: Reputation: 30
Searching a text file - complicated


have a question on how to grep (sed or awk) thru a file and pull back 2 lines. Line 1 has an error code and time stamp, line 2 which is directly below it has a string that i am searching for. How can I search and pull out line 2 to a file and also bring the line above it?
 
Old 12-16-2003, 10:43 AM   #2
jkobrien
Member
 
Registered: Jun 2003
Location: Dublin, Ireland
Distribution: Slackware, LFS, Ubuntu, RedHat, Slamd64
Posts: 507

Rep: Reputation: 30
Hi,

'man grep' would have answered this for you.

'grep -B 2 <regexp> <file>'

John
 
Old 12-16-2003, 10:45 AM   #3
dexter2
LQ Newbie
 
Registered: Nov 2003
Distribution: Red Hat Linux
Posts: 7

Rep: Reputation: 0
grep -A2 'error_code' filename

ll show actual line and 1 line After-context that, same way you can try '-B1' - to see 1 line Before-context, and '-1' for Before & After context.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
text searching sopiaz57 Linux - Software 4 06-02-2005 01:00 PM
Searching text files by content will103 Linux - Software 1 01-24-2005 07:43 AM
searching inside text files minm Linux - Newbie 2 01-08-2005 11:56 PM
C help needed - reading from a complicated text file Keffin Programming 4 01-26-2004 09:32 PM
Complicated Text -> Numbers mickey717 Linux - Newbie 5 10-17-2003 01:41 PM


All times are GMT -5. The time now is 07:35 PM.

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