4 ms·
ag 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,
by pletnes 8y ago
ag 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 agoBecause ripgrep is the reason I discovered Rust (along with xsv for CSV manipulation) and because Andrew asked: % grep "die()" * [...results with functions named die()...] % rg "die()" Error parsing regex I reach for grep when I need to do non-regex searching. Can't remember how to do an fgrep fixed-pattern style ripgrep. great tools andrew: I use them every day and install them first thing on a new box. know that your code really helps
- burntsushi 8y agoAh yes! That is a good one too. That's because grep uses "basic" regexes by default, and this sort of use case is one area where they work nicely. The downside is needing to remember which meta characters need to be escaped. For ripgrep, you can enable literal search the same way you do it in grep: with the -F flag. Thanks for responding!