
For example, the first match “ RuntimeException…” is located at line 2 + 6 – 1 = 7 in the app.log file. Of course, we can get the actual line numbers through this calculation: LINE_NO_BY_GREP + 6 – 1. However, since we piped the tail command’s output to grep, the line numbers reported by the grep command are not the actual line numbers in the original input file. Finally, we look at the (alternation) operator, which is part of the extended regex.

So, let’s execute the command with the -n option: $ tail -n +6 app.log | grep -n 'Exception'Ģ: RuntimeException: File not found: /foo/bar/newFileĤ: TemplateNotFoundException: Template PRETTY not found, loading the default templateĦ: Cleanup job done with IOException: Disk is fullĪs we can see, this time, the command has printed the line numbers of matched lines. Similarly, > anchors the pattern to the end of a word. For example, this helps us locate the log entries with “ Exception” and take a closer look at the stack trace to analyze the cause. However, sometimes, we would like to execute the grep command with the -n option to print the line numbers of each match. RuntimeException: File not found: /foo/bar/newFileĪs we can see, the command above has solved the problem. Next, let’s execute the grep command on the output above to get the required log entries: $ tail -n +6 app.log | grep 'Exception'

#Use grep regex to goet word full#
Cleanup job done with IOException: Disk is full TemplateNotFoundException: Template PRETTY not found, loading the default template RuntimeException: File not found: /foo/bar/newFile
