Since you just want to count occurrences, you may simply zcat
the contents of the file, grep
the portion that describes what you're looking for -- words/time intervals --, and finally sort/count (sort | uniq -c
) the entries. The following would probably suffice:
zcat *.gz | grep <word> | grep -oP "^\d{4}-\d{2}-\d{2};\d{2}" | sort | uniq -c
The above command shall find the lines in your logfile that contains the <word>
you're looking for, extract both date and hour from such entries, and later count the occurrences.
In case you don't want to take into account days/months/years, you may use:
zcat *.gz | grep <word> | grep -oP "^\d{4}-\d{2}-\d{2};\K\d{2}" | sort | uniq -c
The \K
added in the grep
expression is a flag for look-behind in PCRE -- Perl Compatible Regular Expression.