LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Enterprise (https://www.linuxquestions.org/questions/linux-enterprise-47/)
-   -   pulling info from files (https://www.linuxquestions.org/questions/linux-enterprise-47/pulling-info-from-files-489716/)

beeblequix 10-05-2006 11:59 AM

pulling info from files
 
I have a file that log certain events. I'd like to extract certain chunks of the file and redirect into a report. This command --
cat log.file|grep 'error'>report.error.log
-- only pulls that exact line containing the error. But the preceeding and proceeding few lines are also important. Is there a way to
1)search the log for a certain string
2)print the preceeding 5 and proceeding 5 lines
3)similarly to the above, redirect output into a file
?
Ideas?

macemoneta 10-05-2006 12:21 PM

'man grep' says:

Code:

      -A NUM, --after-context=NUM
              Print NUM  lines  of  trailing  context  after  matching  lines.
              Places  a  line  containing  --  between  contiguous  groups  of
              matches.

      -B NUM, --before-context=NUM
              Print  NUM  lines  of  leading  context  before  matching lines.
              Places  a  line  containing  --  between  contiguous  groups  of
              matches.


beeblequix 10-05-2006 12:43 PM

you're awesome. thanks.


All times are GMT -5. The time now is 09:23 AM.