LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Searching a text file - complicated (http://www.linuxquestions.org/questions/linux-general-1/searching-a-text-file-complicated-126350/)

cyph3r7 12-16-2003 11:21 AM

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?

jkobrien 12-16-2003 11:43 AM

Hi,

'man grep' would have answered this for you.

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

John

dexter2 12-16-2003 11:45 AM

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.


All times are GMT -5. The time now is 05:36 AM.