Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to see the output in a logfile greped by only one domain but also the following two lines.


tail -f /var/log/apache2/modsec_audit.log |grep mydomain.de

this shows all lines, that contain "mydomain.de" but the important information is in the line below the line, where the domain is included

share|improve this question
up vote 15 down vote accepted

grep has extra options to define how many lines before and after the result:

  • -A (after)
  • -B (before)
  • -C (context [before + after])

So in your case you need -A:


the above command prints NUMBER of lines after YOURDOMAIN in file.

share|improve this answer
Please note, however, that this is a GNU extension. If you're on Linux, your grep definitely has this option. If you're not, you better check. – Leonid Feb 4 '13 at 8:14
If you're on GNU/Linux. This is one of those cases where "GNU/Linux" is not only correct, it's also highly adequate ;-) – njsg Feb 4 '13 at 8:46
I agree, But nowadays some of OSes uses some of GNU extension in a lot of appl. gcc or ... – PersianGulf Feb 4 '13 at 9:19

Try passing number of context lines to grep.

| grep -C 5

will print 5 lines before and after the match.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.