grep line above and below
Hi,
I have to parse a very large file and I want to use the command grep (or any other tool). I have to check in a log line the word "FAILED", print the line above and below. For example: --------- id : 15 Satus : SUCESS Message : no problem --------- id : 15 Satus : FAILED Message : connection error --------- And I need to print only id : 15 Satus : FAILED Message : connection error Thank you for your help ! |
Use grep -A1 -B1 ^id file_name
Quote:
|
Code:
grep -C 1 FAILED name_of_the_file Code:
grep -1 FAILED name_of_the_file |
See here (example 8) using awk
|
Thanks sycamorex !
It really works good ! |
I know it's considered rude to tell you to RT:)M, the options suggested are in the 1st 6 in the man page:
Quote:
BTW, grep is one of those man pages that should be re-read regularly. |
Quote:
|
All times are GMT -5. The time now is 04:07 PM. |