News for hackers. Stuff that matters.
Re:What I Learned from porting my projects to FreeBSD by agambrahma on Sunday October 28, 2018 @01:37AM (#18319322)
> 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`)

Re:What I Learned from porting my projects to FreeBSD by Sir_Cmpwn on Sunday October 28, 2018 @08:30AM (#18320330)
grep is standardized.

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.

Re:What I Learned from porting my projects to FreeBSD by andrewprock on Sunday October 28, 2018 @02:02AM (#18319369)
At the very least ag does not handle large files. It bails with an error after the file gets too big.
Re:What I Learned from porting my projects to FreeBSD by shakna on Sunday October 28, 2018 @03:02AM (#18319470)
It 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'
Re:What I Learned from porting my projects to FreeBSD by sebcat on Sunday October 28, 2018 @05:46AM (#18319888)

    ag Needle < haystack
No need for cat
Re:What I Learned from porting my projects to FreeBSD by torstenvl on Sunday October 28, 2018 @07:31AM (#18320190)
Your version requires fewer keystrokes. It's also mental model-breaking and un-Unixy. Pipes, my good man! Pipe everything to everything!
Re:What I Learned from porting my projects to FreeBSD by muxator on Sunday October 28, 2018 @08:09AM (#18320287)
How 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/Redirecti...

Re:What I Learned from porting my projects to FreeBSD by twic on Sunday October 28, 2018 @09:28AM (#18320496)
No. Useless Use of Cat is sufficiently unidiomatic that there is an award for it:

http://porkmail.org/era/unix/award.html

Re:What I Learned from porting my projects to FreeBSD by torstenvl on Sunday October 28, 2018 @12:06PM (#18321237)
No. 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.
Re:What I Learned from porting my projects to FreeBSD by xorcist on Sunday October 28, 2018 @03:03PM (#18322297)
If the most logical syntax is

  grep needle haystack
Surely

  grep needle < haystack
is much closer to that form than

  cat haystack | grep needle
Re:What I Learned from porting my projects to FreeBSD by rleigh on Sunday October 28, 2018 @09:37AM (#18320520)
Mm, input redirection with the shell is the very epitomy of basic Unix functionality.
Re:What I Learned from porting my projects to FreeBSD by BenjiWiebe on Sunday October 28, 2018 @01:21PM (#18321676)
< haystack ag Needle

Will work too, and now it's in the logical order.

Re:What I Learned from porting my projects to FreeBSD by xorcist on Sunday October 28, 2018 @04:12AM (#18319643)
Why? 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.

Re:What I Learned from porting my projects to FreeBSD by SSLy on Sunday October 28, 2018 @05:42AM (#18319883)
Re:What I Learned from porting my projects to FreeBSD by xorcist on Sunday October 28, 2018 @02:39PM (#18322107)
Right, 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.

Re:What I Learned from porting my projects to FreeBSD by burntsushi on Monday October 29, 2018 @08:37AM (#18326971)
ripgrep 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/ specifically: 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.

Re:What I Learned from porting my projects to FreeBSD by flurrything on Monday October 29, 2018 @09:11AM (#18327198)
Could ripgrep offer a POSIX compatible mode?
Re:What I Learned from porting my projects to FreeBSD by burntsushi on Monday October 29, 2018 @09:32AM (#18327354)
It "could" in the sense that it's of course technically possible. But it's a _ton_ of work, and it's not clear to me that it would actually be beneficial. GNU grep is doing just fine as far as I can tell at being a POSIX compatible grep.

ripgrep is split into libraries, so if someone wanted this, they could just go do it themselves. :-) It would actually be pretty easy to get something that smells like POSIX. But the details make up a very long tail, and some of those tasks are fairly significant (supporting BRE syntax, supporting POSIX-style alternations, supporting POSIX locales).

Re:What I Learned from porting my projects to FreeBSD by MaxBarraclough on Sunday October 28, 2018 @06:37AM (#18320030)
> 3 cycles/byte in the trivial case

Shouldn't it be less than that in the best case, by means of Boyer–Moore?

Re:What I Learned from porting my projects to FreeBSD by xorcist on Sunday October 28, 2018 @02:59PM (#18322274)
Per processed byte, IIRC.
Re:What I Learned from porting my projects to FreeBSD by rurban on Sunday October 28, 2018 @02:39AM (#18319422)
grep is assumed to be installed everywhere.

ag and gmake and several GNU or linux-specific extensions not.

Re:What I Learned from porting my projects to FreeBSD by pbhjpbhj on Sunday October 28, 2018 @09:08AM (#18320428)
-P being PCRE (Perl regex).

By ag, do you mean ack-grep (https://beyondgrep.com/install/)?

Re:What I Learned from porting my projects to FreeBSD by twic on Sunday October 28, 2018 @09:25AM (#18320484)
Re:What I Learned from porting my projects to FreeBSD by kzrdude on Sunday October 28, 2018 @06:11AM (#18319953)
They do different things. So we need both :)