ripgrep [Fast grep with better defaults and customization]

Submit command line tools that you find here.
Post Reply
Message
Author
User avatar
vevy
Posts: 795
Joined: Tue Sep 10, 2019 11:17 am

ripgrep [Fast grep with better defaults and customization]

#1 Post by vevy »

Since grep tools are all the rage! :P I thought I'd add a very good one that hasn't been mentioned once in the forums!


https://github.com/BurntSushi/ripgrep
"ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern. By default, ripgrep will respect your .gitignore and automatically skip hidden files/directories and binary files. ripgrep has first class support on Windows, macOS and Linux, with binary downloads available for every release. ripgrep is similar to other popular search tools like The Silver Searcher, ack and grep."
Image


Is it really faster than everything else?

Generally, yes. A large number of benchmarks with detailed analysis for each is available on my blog.
Why should I use ripgrep?
  • It can replace many use cases served by other search tools because it contains most of their features and is generally faster. (See the FAQ for more details on whether ripgrep can truly replace grep.)
  • Like other tools specialized to code search, ripgrep defaults to recursive directory search and won't search files ignored by your .gitignore/.ignore/.rgignore files. It also ignores hidden and binary files by default. ripgrep also implements full support for .gitignore, whereas there are many bugs related to that functionality in other code search tools claiming to provide the same functionality.
  • ripgrep can search specific types of files. For example, rg -tpy foo limits your search to Python files and rg -Tjs foo excludes JavaScript files from your search. ripgrep can be taught about new file types with custom matching rules.
  • ripgrep supports many features found in grep, such as showing the context of search results, searching multiple patterns, highlighting matches with color and full Unicode support. Unlike GNU grep, ripgrep stays fast while supporting Unicode (which is always on).
  • ripgrep has optional support for switching its regex engine to use PCRE2. Among other things, this makes it possible to use look-around and backreferences in your patterns, which are not supported in ripgrep's default regex engine. PCRE2 support can be enabled with -P/--pcre2 (use PCRE2 always) or --auto-hybrid-regex (use PCRE2 only if needed). An alternative syntax is provided via the --engine (default|pcre2|auto-hybrid) option.
  • ripgrep supports searching files in text encodings other than UTF-8, such as UTF-16, latin-1, GBK, EUC-JP, Shift_JIS and more. (Some support for automatically detecting UTF-16 is provided. Other text encodings must be specifically specified with the -E/--encoding flag.)
  • ripgrep supports searching files compressed in a common format (brotli, bzip2, gzip, lz4, lzma, xz, or zstandard) with the -z/--search-zip flag.
  • ripgrep supports arbitrary input preprocessing filters which could be PDF text extraction, less supported decompression, decrypting, automatic encoding detection and so on.
In other words, use ripgrep if you like speed, filtering by default, fewer bugs and Unicode support.
Portable by default (no settings, bu can can accept config files and pattern files).
It is also really customizable in options and looks (of results).

The developer doesn't accept donations!
Last edited by vevy on Sun Nov 08, 2020 7:29 am, edited 3 times in total.

User avatar
vevy
Posts: 795
Joined: Tue Sep 10, 2019 11:17 am

Re: ripgrep [Fast grep with better defaults and customization]

#2 Post by vevy »

A comparison:
Please remember that a single benchmark is never enough! See my blog post on ripgrep for a very detailed comparison with more benchmarks and analysis.
Tool Command Line count Time
ripgrep (Unicode) rg -n -w '[A-Z]+_SUSPEND' 452 0.136s
git grep git grep -P -n -w '[A-Z]+_SUSPEND' 452 0.348s
ugrep (Unicode) ugrep -r --ignore-files --no-hidden -I -w '[A-Z]+_SUSPEND' 452 0.506s
The Silver Searcher ag -w '[A-Z]+_SUSPEND' 452 0.654s
git grep LC_ALL=C git grep -E -n -w '[A-Z]+_SUSPEND' 452 1.150s
ack ack -w '[A-Z]+_SUSPEND' 452 4.054s
git grep (Unicode) LC_ALL=en_US.UTF-8 git grep -E -n -w '[A-Z]+_SUSPEND' 452 4.205s



There is also rga: https://github.com/phiresky/ripgrep-all
rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.

User avatar
rbon
Posts: 361
Joined: Wed Mar 28, 2007 2:16 am
Location: Italy

Re: ripgrep [Fast grep with better defaults and customization]

#3 Post by rbon »

Some details about ripgrep:
• ripgrep corrent release: 12.1.1
• ripgrep GitHub download page: https://github.com/BurntSushi/ripgrep/r ... tag/12.1.1
• direct download archive 'ripgrep-12.1.1-x86_64-pc-windows-msvc.zip': https://github.com/BurntSushi/ripgrep/r ... s-msvc.zip
• direct download archive 'ripgrep-12.1.1-x86_64-pc-windows-gnu.zip': https://github.com/BurntSushi/ripgrep/r ... ws-gnu.zip

Archive sizes:
• Microsoft Visual C++: 1.75 MB
• GNU MinGW: 9.08 MB
MinGW archive do not require runtime.

Note
Windows binaries are available either as built with MinGW (GNU) or with Microsoft Visual C++ (MSVC). When possible, prefer MSVC over GNU, but you'll need to have the Microsoft VC++ 2015 redistributable installed.*
* Latest supported Visual C++ downloads are: 'Visual Studio 2015, 2017 and 2019'
• Microsoft download page: https://support.microsoft.com/en-us/hel ... -downloads
• Softpedia: https://www.softpedia.com/get/Programmi ... 2017.shtml
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." - Rick Cook.

User avatar
vevy
Posts: 795
Joined: Tue Sep 10, 2019 11:17 am

Re: ripgrep [Fast grep with better defaults and customization]

#4 Post by vevy »

Thanks for the info, rbon!

User avatar
webfork
Posts: 10818
Joined: Wed Apr 11, 2007 8:06 pm
Location: US, Texas
Contact:

Re: ripgrep [Fast grep with better defaults and customization]

#5 Post by webfork »

Another welcome addition to ripgrep: rga

ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.
https://phiresky.github.io/blog/2019/rg ... -epub-jpg/
rga is a line-oriented search tool that allows you to look for a regex in a multitude of file types. rga wraps the awesome ripgrep and enables it to search in pdf, docx, sqlite, jpg, zip, tar.*, movie subtitles (mkv, mp4), etc.

User avatar
rbon
Posts: 361
Joined: Wed Mar 28, 2007 2:16 am
Location: Italy

Re: ripgrep [Fast grep with better defaults and customization]

#6 Post by rbon »

ripgrep v.13.0.0 has been released at June 12, 2021:
ripgrep 13 is a new major version release of ripgrep that primarily contains bug fixes, some performance improvements and a few minor breaking changes.
There is also a fix for a security vulnerability on Windows.
(CVE-2021-3013 https://cve.mitre.org/cgi-bin/cvename.c ... -2021-3013).

In case you haven't heard of it before, ripgrep is a line-oriented search tool that recursively searches the current directory for a regex pattern.
By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files.
Links:
• ripgrep GitHub page: https://github.com/BurntSushi/ripgrep
• ripgrep GitHub download page: https://github.com/BurntSushi/ripgrep/r ... tag/13.0.0
• direct download archive 'ripgrep-13.0.0-x86_64-pc-windows-msvc.zip': https://github.com/BurntSushi/ripgrep/r ... s-msvc.zip
• direct download archive 'ripgrep-13.0.0-x86_64-pc-windows-gnu.zip': https://github.com/BurntSushi/ripgrep/r ... ws-gnu.zip

Changelog of ver. 13.0.0 on GitHub download page: https://github.com/BurntSushi/ripgrep/r ... tag/13.0.0

Archive sizes:
• Microsoft Visual C++: 1.65 MB
• GNU MinGW: 9.36 MB
MinGW archive do not require runtime.

Note
Windows binaries are available either as built with MinGW (GNU) or with Microsoft Visual C++ (MSVC). When possible, prefer MSVC over GNU, but you'll need to have the Microsoft VC++ 2015 redistributable installed.*
* Latest supported Visual C++ downloads are: 'Visual Studio 2015, 2017, 2019 and 2022'
• Microsoft download page: https://support.microsoft.com/en-us/hel ... -downloads
• file name for x86: VC_redist.x86.exe
• file name for x64: VC_redist.x64.exe
• Latest version number (July 10, 2021): ver. 14.29.30135.0
• Softpedia: https://www.softpedia.com/get/Programmi ... 2017.shtml
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning." - Rick Cook.

Post Reply