Show only N matches at end of file #1888
-
Hello, I would like to know if I can use
I'm familiar with options Is there an option with Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Why do I want this?
I don't care about 2455 of those matches; I only want to know the status of the last ten lines in my file. |
Beta Was this translation helpful? Give feedback.
-
There is no way, no. To answer the next natural question: no, I don't think I will add it. In order to know if a match is part of the last N matches, you have to know where the last match is. In order to know where the last match is, you need to search the entire input. Thus, by necessity, implementing this feature requires buffering the last N matches in memory and only printing them once the search has completed. ripgrep isn't really set up to do that. Instead, I suggest using |
Beta Was this translation helpful? Give feedback.
-
For anyone who comes here still looking for a way to do this for several files, it can approximately be done on unix systems using
This will run
or, if you have a very large number of matching files:
If you do have a multi-line pattern or care about line numbers, you'll probably want to just use the shell:
Thanks for making such a great tool, @BurntSushi. |
Beta Was this translation helpful? Give feedback.
There is no way, no.
To answer the next natural question: no, I don't think I will add it. In order to know if a match is part of the last N matches, you have to know where the last match is. In order to know where the last match is, you need to search the entire input. Thus, by necessity, implementing this feature requires buffering the last N matches in memory and only printing them once the search has completed. ripgrep isn't really set up to do that.
Instead, I suggest using
tail
:rg foo | tail -n 10
will print only the last ten matches.