5 ms·
If you don't mind me asking, in roughly what cases do you reach for grep instead of ag || ack? Is it a familiarity thing, or specific features or something else
by burntsushi 8y ago
If you don't mind me asking, in roughly what cases do you reach for grep instead of ag || ack? Is it a familiarity thing, or specific features or something else?
- earenndil 8y agoNot the gp, but I generally use ripgrep when I want to find something manually, and regular grep in a script.
- burntsushi 8y agoAh yeah, me too! That's a good one.
- vram22 8y agoWhy? Does ripgrep not work as well (or better) than grep in a script? And if so, why not? Or is because you deploy your scripts to other machines where ripgrep may not be present, but grep will?
- jolmg 8y agoScripts tend to be shared, so portability matters. grep alternatives, while great for interactive use, are generally not worth being an extra dependency to install.
- earenndil 8y agoGrep is: * Deterministic * Standard * Written in c * Equally performant (where it matters) * Doesn't show colour or line numbers unless I tell it to * Doesn't watch .gitignores unless I tell it to
- executesorder66 8y agoI use rg on all my scripts that I won't be sharing with others. Anything that needs to be used by other people / needs to be run on any machine that I don't control, uses grep instead.
- pletnes 8y agoag is made to search code specifically. grep is a more general purpose text search tool and better suited (imho) for handling data (in contrast to code). Also, it’s always installed. I’ve never been on a machine with ag unless if I’ve installed it myself.
- burntsushi 8y agoErrmm, yes, I'm familiar with the difference in motivations behind the tools. I guess what I'm looking for is specific examples of things that cause you to use grep instead of ag. Ubiquity is a good one. But let's say you have both ag and grep. When do you reach for one and why? (I should have said this in my first comment, but I'm the author of ripgrep, and I'm just generally interested in learning more about the differing use cases for these tools, in the words of users. I certainly have my own ideas about the question!)
- adambyrtek 8y agoPersonally, I often use grep to filter results of a pipeline: some | commands | grep ERROR In fact I do this so often that I have it aliased to g: alias g=grep Maybe I could achieve the same with ack/ag/ripgrep, but I somehow mentally associate these tools with searching over a filesystem.
- jolmg 8y agoThey're really meant for the same thing. You can also search the filesystem with grep by using -R and providing a path explicitly like `grep -R pattern .`. EDIT: The real differences (at least the most important ones for me) between grep and these tools are 1) they format filesystem searches better for human viewing, 2) they provide more useful defaults, 3) in the case of ag, you can specify a max line width to avoid the terminal being filled by a matching line that has a ridiculous length, which typically happens with generated files, 4) they're supposed to be faster although I personally don't have searches big enough to notice the difference, but I imagine it's a big deal to others.
- sstanfie 8y ago
- jolmg 8y agoWell there's the portability of grep which is better for scripts. Besides that, most if not all times I do a simple `ag pattern file`, I'm interested only in the results and not in the location. I'm probably preparing the pattern to output something to provide to another command via stdin or substitution and at those times (which is also in the interactive command line), I want to see exactly what I'm going to pass in. To remove the numbers ag adds by default, I have to use --nonumbers, which is weirdly long given that one of the main benefits of ag is the brevity of the commands (ag is short and easy to type, no need to include options -r, -i, -P, or -n (when needed)). Instead of using that option, I just switch to grep. I really wish ag changed that default to be consistent with grep and ack or at least change the way its options are negated, like making it a short option and negating like +N. EDIT: I just saw your comment where you stated you're the author of rg. I honestly haven't tried it before until now. It seems you also chose to output line numbers by default in that case, but it's nice that you have -N. If you don't mind me asking, do you have an option like ag's undocumented -W which allows specifying a max line width for which a matching line is displayed? Regularly when searching a hierarchy a match happens on a generated file where everything is on a single line and so my terminal prints the millions of characters line. -W displays an bracketed ellipsis once the max width is reached on a line.
- burntsushi 8y ago> It seems you also chose to output line numbers by default in that case, but it's nice that you have -N. Right. When you run ripgrep with its output connected to a tty, then its output is "prettified." That means results are grouped by file, colorized and include line numbers. But if you aren't connected to a tty, then ripgrep reverts to the standard grep format (e.g., no line numbers). This means you should be able to use ripgrep in pipelines pretty much exactly like you would use grep. It just does the right thing. You can test this easily by comparing the output of `rg <pattern>` with `rg <pattern> | cat`. ag also does this to some extent (by disabling grouping and colors), but does still include line numbers in most cases. > do you have an option like ag's undocumented -W which allows specifying a max line width for which a matching line is displayed? Yes. That's the -M/--max-columns option. I have that set by default in my config: $ cat ~/.ripgreprc --max-columns=500 --colors=match:bg:0xff,0x7f,0x00 --colors=match:fg:white --colors=line:none --colors=line:fg:magenta --colors=path:fg:green --type-add=got:*_test.go Note: $ echo $RIPGREP_CONFIG_PATH /home/andrew/.ripgreprc