Live data from Hacker News

Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

beyondgrep.com

41–50 of 101 posts

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#41
post #40

Here to plug using `--passthru`/`--passthrough`: it will print all lines, but highlight matches. I often do things like this to watch an output log, but highlight all entries with the string PLUGH in them: tail -F output.log | ag --passthrough '.*PLUGH.*'

I wondered what that option could be useful for, thanks!

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#42

This chart doesn't compare speed. Until rg, I didn't grep much because I generally search through a lot of files. rg cuts through them in no time.

No, the chart doesn't compare speed. Lord knows there have been many comparisons of the speeds of grep-alikes, but nobody has written up a comparison of features.

For me, raw speed is not as important as a rich feature set to support my code spelunking.

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#43

Earlier quoted context omitted.

The table doesn't yet distinguish between lacking a command line flag due to absence of a feature vs due to the feature being the default. This is similar to the situation with case-sensitive search in GNU grep, which ends up with a blank cell even though it is the default. See: https://github.com/beyondgrep/website/issues/72 It's a fair criticism but I don't think it is designed to be misleading.

Maybe not designed to be misleading, but misleading nonetheless. For `grep`, `grep -i needle` is (approximately) equal to `ack/ag needle`, but looking at the table I wouldn't think grep supports case sensitivity.

I've updated the phrasing so it says "Re-enable case-sensitive search over case-insensitve or smart-case search".

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#44
post #40

Here to plug using `--passthru`/`--passthrough`: it will print all lines, but highlight matches. I often do things like this to watch an output log, but highlight all entries with the string PLUGH in them: tail -F output.log | ag --passthrough '.*PLUGH.*'

You can achieve that in almost any of these tools (including old-school grep) by matching against something with zero width, like this:

  grep '^|.*PLUGH.*'

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#45

The chart was created by Andy Lester, the creator of ack, who thinks that more open source projects should point to their "competing" projects because it's not really a competition: http://blog.petdance.com/2018/01/02/the-best-open-source-pro...

Emphasis mine- Excerpt: "Some might say that ag and ripgrep and any of the other tools I list on beyondgrep.com are competing projects, but I think that way of thinking is wrong. It’s only a competition if you see it as a competition. I’m not competing against anyone for anything: Clicks, dollars, popularity, etc. If someone uses ripgrep instead of ack, it doesn’t hurt me. It’s the difference between an abundance vs.…

What is woo-woo space?

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#46

A nice feature of ag is the ability to limit the search to a certain file type. E.g. to only search ruby files: ag --ruby foo . To see a list of supported types and the matching file extensions: ag --list-file-types . Just checked and rg does have something similar, but you need to specify the type as an argument to a flag: rg --type ruby foo .

You can shorten it with -t: -tc, -tphp, -truby, -tsh. Then it's actually the same amount of characters as with ag.

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#47
post #14
post #3

as a long time user of `find . -name "*.foo" -exec grep -Hin {} \;` moving to ack has been great! I love the syntax and the speed and the fact that it actually respects your ignore files. ripgrep is great too. ag on the other hand is recommended by everyone but doesn't seem to respect ignores or understand modern ignore syntax. give it a pass. https://github.com/ggreer/the_silver_searcher/issues/385 its been over 4 y…

Spawning a separate grep for each file? That's terribly inefficient. At least use xargs which will run one process on as many files as possible. But you know there's a -r for recursive, right? And unless you are using some historic relic of grep that is not GNU or BSD and doesn't understand the --include option you can just do: grep -rin "needle" --include "*.foo" .

I use something along the lines of

    find . -iname '.*' -prune -o -iname '*.foo' -exec grep needle {} +
I don't want to have to learn 10 different command syntaxes for walking directory trees, so find works well. The "+" terminator of find's exec is similar to xargs, but preserves the flexibility of find's exec.

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#48
post #35

Earlier quoted context omitted.

At the least, I recommending moving past `find . --name '*.foo' -exec grep` pattern if you can help it. Modern file searchers, of which `ag` is one among others, accepts `--filenametype` argument and skips the `.git` subdirectory if it exists (by default, can be toggled), so `ag --python needle` will recursively search for needle in the the current working tree in all files whos filenames end in `.py`. Yes, you could…

Or just use "grep". It is what it's there for. Use --include and --exclude-dirs to do what you describe. (The latter is a good idea to set in your GREP_OPTIONS, unless you actually search .git directories.)

GREP_OPTIONS is deprecated in GNU grep since i think 2.20. It will be removed in a future version, and until then it's going to print an irritating warning message every time you use it.

(I don't think there's any such plan for the various BSD greps, so if you use those exclusively you're probably fine.)

Re: Feature comparison of ack, ag, git-grep, GNU grep and ripgrep

#49
post #40

Here to plug using `--passthru`/`--passthrough`: it will print all lines, but highlight matches. I often do things like this to watch an output log, but highlight all entries with the string PLUGH in them: tail -F output.log | ag --passthrough '.*PLUGH.*'

The equivalent in grep is '--line-buffered'.
Post reply on HN