Genivia / ugrep

NEW ugrep 6.5: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.59k stars 109 forks source link

Complementary option to --max-count (Enhancement) #292

Closed acelticsfan closed 10 months ago

acelticsfan commented 1 year ago

The --max-count feature is nice. It's basically like ugrep 'PATTERN' - | head .

I'm proposing a complementary feature that is equivalent to ugrep 'PATTERN' - |tail.

Perhaps it could be called --max-count-tail, whereby one only gets the last N matching lines of a stream or file.

In a log file, some times the only data I'm interested in is the most recent data at the bottom of the file.

genivia-inc commented 1 year ago

That's a neat idea. I will keep this in mind and put it on a TODO list. However, I can't guarantee it's included in an update, because there will be some (performance) caveats to implement a tail version of max count.

Note that -K NUM skips NUM lines before searching, so that's like tail -n NUM FILE | ugrep PATTERN, but ugrep -K NUM PATTERN FILE outputs the correct line numbers of FILE.

acelticsfan commented 1 year ago

Thanks. Regarding performance, that makes sense since you would still have to read the whole file. ugrep is fast enough that for me it wouldn't really matter.

genivia-inc commented 10 months ago

I thought hard and long about this and considered some initial designs.

But the addition of a tail-like match count to count matches from the end is not really feasible to implement without negatively impacting the overall design and speed of ugrep.

I would think that a simpler use by piping the ugrep output to tail works reasonably well, to get the last matching lines that ugrep outputs as matches. Then use ugrep --color=always to force color output to tail.

acelticsfan commented 10 months ago

I understand. Thanks for the pointers.