Home

Awesome

Build Status Coverage Status MetaCPAN Release

NAME

dategrep - print lines matching a time range

SYNOPSIS

dategrep --start "12:00" --end "12:15" syslog
dategrep --end "12:15" --format "%b %d %H:%M:%S" syslog
dategrep --last-minutes 5 syslog
cat syslog | dategrep --end "12:15"

DESCRIPTION

dategrep reads a file and prints every line with a timestamp that falls into a user defined time range.

When invoked on a normal file, dategrep uses a binary search to find the first matching line. It can also read from stdin and compressed files but in this case it has to parse the timestamp of every line until the first matching line is found.

As soon as it finds the first date not in the range, dategrep terminates.

dategrep can already parse some common logs formats like rsyslog and apache common log format. Additional formats can be used by supplying a strptime(3) format string.

See UPGRADING if you used dategrep before. dategrep sees currently a lot of change, so this version might be less reliable as version 0.58. Please submit bug reports if anything unusual happens.

EXAMPLES

Print all lines between 12:00 and 12:15:

dategrep --start 12:00 --end 12:15 syslog

Without --start, print all lines after epoch:

dategrep --end 12:15 syslog

Using a user supplied format string:

dategrep --format "%b %d %H:%M:%S" syslog

Printing all lines from the last 5 minutes.

dategrep --last-minutes 5 syslog

Reading from compress files or stdin:

cat syslog | dategrep --end 12:15
dategrep --end 12:15 syslog.gz

OPTIONS

ENVIRONMENT

COMPRESSED FILES

dategrep has only minimal support for compressed files. If any file in ARGV has an extension like .z,.gz,.bz2,.bz, dategrep will call zcat or bzcat respectively and read from it like from stdin.

LIMITATION

dategrep expects the files to be sorted. If the timestamps are not ascending, dategrep might be exiting before the last line in its date range is printed.

Compressed files are just piped into dategrep via bzcat or zcat.

SEE ALSO

strptime(3)

INSTALLATION

The easiest way to install dategrep is to just build it as a standalone script:

./build-standalone
./dategrep

Check https://github.com/mdom/dategrep/releases/latest for prebuild scripts.

It is possible to install this script via perl normal install routines.

perl Build.PL && ./Build && ./Build install

Or via CPAN:

cpanm App::dategrep

yamlCase maintains an Dockerfile for dategrep at https://github.com/yamlCase/dategrep/tree/dockerfile_poc.

UPGRADING

dategrep after version 0.58 uses a new library to parse dates. Most time conversion specifiers are compatible, but it's probably better to check the manual for valid specifiers. In addition the format for specifying date offsets has changed.

COPYRIGHT AND LICENSE

Copyright 2014 Mario Domgoergen <mario@domgoergen.com>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.