-1

I want to see the logs where log level is ERROR and I want to see the stackTrace but when I input like below cat app.log | grep ERROR I can't see the stackTrace Is there a way to see several lines under the greped line?

2 Answers2

1

You can use -A NUM as part of the grep options.

For example: cat app.log | grep ERROR -A 10 will print 10 lines after the matching line(s).

From the grep man page:

-A NUM, --after-context=NUM Print NUM lines of trailing context after matching lines. Places a line containing a group separator (described under --group-separator) between contiguous groups of matches. With the -o or --only-matching option, this has no effect and a warning is given.

badjr
  • 2,166
  • 3
  • 20
  • 31
1
grep -A 3 app.log
  • -A 3 ("after") prints matching line, and 3 more below (4 lines total)
  • -B 3 ("before") prints matching line, and 3 more before (4 lines total)
  • -C 3 ("context") prints matching line, and 3 above and 3 below (7 lines total)
dan
  • 4,846
  • 6
  • 15