grep
is pre-installed on *nix systems and is a tool that programmers often use in their daily work. My recent work involves a lot of large text processing, and grep doesn’t work very fast. So I used ripgrep, a tool that runs much faster. This article is mainly excerpts from the use of their usual may be used.
Install
Just find your corresponding system command in the GitHub Repo guide to install it, one line command.
After installation, the executable command for ripgrep is rg
.
Common parameters
General search
|
|
By default, the standard output will highlight your search term and each line will be preceded by a line number. Rest assured, however, that redirecting to another text does not include line numbers.
If you do not want the line numbers to be output, use `-N.
|
|
Count the number of rows
|
|
And conditions
A ha, not yet supported, many users have been mentioning this requirement for a long time. Let’s see when the stubborn author will allow it to be added. You can follow this Issue.
I can only filter again after the pipeline, --color always
is so that the first search term can be highlighted too.
|
|
Or conditionals
Use multiple -e arguments as conditions. As long as any search term is matched, it will be matched.
|
|
Stop when you reach N results
In many cases, we know that there are only N matches, and to save time, we want to match enough items to stop searching further.
|
|
Regularity
The following -e
can be left out, because the default treats the search term as a regular.
If you wish to treat the search term as ordinary text, use -F
, why treat it as a regular by default, magical design, maybe file search uses regulars universally?
|
|
Replace text
Replaces the searched text with the one you specify before output. Use -r
.
Note that this parameter does not change your original text, it just replaces it when outputting.
|
|
If you wish to implement replacing a specific text of the original file, you can do so.
|
|
The -passthru
argument will standardize the output of unmatched lines as well.