5 ms·
> FreeBSD’s grep does not have a "-P" flag by default (I continue to wonder what's stopping everyone from just ditching `grep` altogether and switching to `ag`
by agambrahma 8y ago
> FreeBSD’s grep does not have a "-P" flag by default
(I continue to wonder what's stopping everyone from just ditching `grep` altogether and switching to `ag`/`rg`)
- andrewprock 8y agoAt the very least ag does not handle large files. It bails with an error after the file gets too big.
- shakna 8y agoIt can crash, on large files, particularly on macOS because mmap is disabled by default. But that should go away by streaming the file. e.g. cat haystack | ag 'Needle'
- sebcat 8y agoag Needle < haystack No need for cat
- torstenvl 8y agoYour version requires fewer keystrokes. It's also mental model-breaking and un-Unixy. Pipes, my good man! Pipe everything to everything!
- muxator 8y agoHow come knowing how to redirect stdin is un-Unixy? Pipes are a good tool, and so are many others. Having a good command of other basic mechanisms of the shell is going to hugely pay off, try to have a brief shot if you want [0]. [0] https://www.gnu.org/software/bash/manual/html_node/Redirections.html https://www.gnu.org/software/bash/manual/html_node/Redirecti...
- twic 8y agoNo. Useless Use of Cat is sufficiently unidiomatic that there is an award for it: http://porkmail.org/era/unix/award.html http://porkmail.org/era/unix/award.html
- torstenvl 8y agoNo. Being smug doesn't make someone right. Especially when the smug person is advocating a special case. Special cases are inherently wrong, even when they "save" a process.
- xorcist 8y agoIf the most logical syntax is grep needle haystack Surely grep needle < haystack is much closer to that form than cat haystack | grep needle
- rleigh 8y agoMm, input redirection with the shell is the very epitomy of basic Unix functionality.
- BenjiWiebe 8y ago< haystack ag Needle Will work too, and now it's in the logical order.
- rurban 8y agogrep is assumed to be installed everywhere. ag and gmake and several GNU or linux-specific extensions not.
- xorcist 8y agoWhy? They're not compatible and not a drop-in replacement. They're also likely a little bit slower, especially on large datasets. It's really hard to beat GNU grep. (Which is famously 3 cycles/byte in the trivial case. Great exercise though.) But for the most part performance is secondary to feature partity.
- SSLy 8y agoFWIW rg is faster than gnu grep https://github.com/BurntSushi/ripgrep#quick-examples-comparing-tools https://github.com/BurntSushi/ripgrep#quick-examples-compari...
- xorcist 8y agoRight, by "very hard to beat" I didn't mean to imply it was somehow impossible. Looking at the whole benchmark that that page links to, the difference is within a few percent for the actual searching, but it is also the only software in the author's own benchmark that is even close. The other software that was mentioned in the comment above is some 5x worse. Nobody is going to change the standard grep for performance reasons.
- burntsushi 8y agoripgrep author here. It really depends on what you're searching. In some types of searches, GNU grep can get very very slow. The page you were linked to includes some benchmarks for that. In particular, cases where you're searching large amounts of non-ASCII (but UTF-8) text. There are some benchmarks for that case here: https://blog.burntsushi.net/ripgrep/ https://blog.burntsushi.net/ripgrep/ specifically: https://blog.burntsushi.net/ripgrep/#subtitles-no-literal https://blog.burntsushi.net/ripgrep/#subtitles-no-literal Also, it's probably not about "feature parity" per se, but standardization. In terms of feature parity, there is very little that grep can do that, say, ripgrep cannot. But there is quite a bit that ripgrep can do that grep cannot do, mostly by design. "replacing" grep with ripgrep has at least a dual meaning, and it is the source of unending miscommunication. In the one sense, I know plenty of people that have replaced grep with ripgrep (or whatever) in daily usage. This is a perfectly valid thing to do. In another sense, nobody is going to replace grep with ripgrep in a distribution because they almost certainly do not want to stop being POSIX compatible. That is, asking to "just replace" grep with ripgrep is equivalent to asking distributors to stop being POSIX compatible in exchange for some other feature that ripgrep provides. That question is a non-starter, but a lot of people either don't realize that or are confusing what it means to "replace" something.
- kzrdude 8y agoThey do different things. So we need both :)
- Sir_Cmpwn 8y agogrep is standardized. http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/gr... Using ag et al in a script makes your script non-portable, which is the opposite of the goal here.
- pbhjpbhj 8y ago-P being PCRE (Perl regex). By ag, do you mean ack-grep (https://beyondgrep.com/install/ https://beyondgrep.com/install/)?
- twic 8y agoag = The Silver Searcher https://github.com/ggreer/the_silver_searcher https://github.com/ggreer/the_silver_searcher