Search code examples
taillogfile

Get first n lines of new input when using tail -f


I'm tailing a log file but I only want the first 3 lines of the new input each time somthing gets added to it.

I've tried tail -f /var/log/webapps/app.name.com.error.log and even piping output of tail -f to sed but neither of them worked the way I wanted.


Solution

  • If you know some content of the first line, you can pipe it with grep and -A

    tail -f LGOFILE | grep "FIRSTLINE" -A 2