-   Linux - General (
-   -   Searching a text file - complicated (

cyph3r7 12-16-2003 10: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 10:43 AM


'man grep' would have answered this for you.

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


dexter2 12-16-2003 10: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 11:38 PM.