Skip to main content

Posts

Showing posts from June, 2022

Navigating the log files

  Often you may find yourselves in the middle of searching for a keyword in your log files.  On the linux environment , you will easily find by using the command            grep 'your keyword' filename.log Sometime you may want to know what happens before and after the occurrence of your keyword.  In the example below I tried to look for an exception using grep command. The output alone is not really helpful to identify the problem that I'm looking for. We need to understand what happened before and after the exception that occurred. The first step is to get the line number of the first occurrence of this error. Let's use the command with grep -n command We can now see the line numbers; 2449 and 2515. The next step is to find out the content of the log few lines adjacent to line 2449 in this example. The following command gives the desired result that is connect of the log file between the lines shown in the example below. sed -n '2440,2460 {  p; }' < nohup.