You can use this retail
command: https://github.com/mwh/retail
It supports regular expressions for starting and stopping output, so you probably want something like:
retail -r STARTPATTERN mylogfile
retail -r STARTPATTERN -u ENDPATTERN -f mylogfile
The -r
option explicitly finds the last instance of the pattern, which is usually what you want.
See also: https://superuser.com/questions/270529/monitoring-a-file-until-a-string-is-found
Here's an example using an Apache error log where Apache has been restarted multiple times, using retail
to extract just the final restart:
$ grep -c "Apache.*resuming normal operations" /var/web/logs/error.log
8
$ retail -r "Apache.*resuming normal operations" /var/web/logs/error.log
[Wed Jul 6 17:12:55.534567 2016] [mpm_prefork:notice] [pid 17965] AH00163: Apache/2.4.4 (Unix) OpenSSL/1.0.1e configured -- resuming normal operations
[Wed Jul 6 17:12:55.534582 2016] [mpm_prefork:info] [pid 17965] AH00164: Server built: Mar 26 2016 12:22:17
[Wed Jul 6 17:12:55.534598 2016] [core:notice] [pid 17965] AH00094: Command line: '/usr/local/apache2/bin/httpd'
Or you can use a regex of "(SIGTERM.* shutting down|SIGHUP.*restart)"
to show everything after the last shutdown or restart attempt.