I'm working with huge log files that accumulate over days that I can't truncate/rotate but need to parse new entries hourly.
I've been using grep
to grab entries with a specific string then counting how many I get and tossing the first N
, where N
is the number of entries
I've already ingested on all prior loops, but of course this means inefficiently grepping the whole file every loop. I'm relatively unix naive, but I feel like there's a more efficient way to do this? I don't think tail
would work because I won't know how many new lines have been written since the last parsing. This post talks of skipping, but using a search string to determine how many lines to skip whereas I'd be looking to supply the skip number as an argument. This one speaks to skipping a specified number of characters on each line, but I'd be looking to skip a specified number of lines.
Any suggestions?
tail -f -n+M file | grep ...
to carry on searching afterwards waiting for more lines to be added. – Stéphane Chazelas Jun 14 '21 at 14:17sed '/start pattern/,$!d; /pattern/!d'
to look forpattern
starting with the first line that matchespattern
. – Stéphane Chazelas Jun 14 '21 at 14:18awk '$0 >= "2021-06-14 10:00" && /pattern/'
if your logs are timestamped like that. – Stéphane Chazelas Jun 14 '21 at 14:19