Suggestion: as a good practice, always use single quotes unless you need double quotes (you've mixed it up in the article)
With GNU grep, you have two options to control how to separate different matching groups: --no-group-separator and --group-separator (see my tutorial for details)
As pointed by others, ripgrep has --passthru option to show entire input file instead of using regex trick. You can also use -E '^|pattern' or -E 'pattern|$' instead of -e option. always color option is useful to highlight multiple terms in different color, see stackoverflow.com/questions/172360... for example
For those interested in detailed learning of GNU grep and ripgrep, I have a book on that: github.com/learnbyexample/learn_gn... (I had a free offer running, but that ended yesterday, bad timing)
Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Very helpful, thanks! I appreciate the input from someone who literally wrote the book.
The —always tip is especially good, because I was not sure that there was ever a good reason for that option. The -e choice of syntax was deliberate, as I think it gives an ever so slight readability boost over the more opaque regex syntax for showing separate patterns, but showing folks that the extended regex flag is available is a good tip. Thanks again!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nicely presented!
Suggestion: as a good practice, always use single quotes unless you need double quotes (you've mixed it up in the article)
With
GNU grep
, you have two options to control how to separate different matching groups:--no-group-separator
and--group-separator
(see my tutorial for details)As pointed by others,
ripgrep
has--passthru
option to show entire input file instead of using regex trick. You can also use-E '^|pattern'
or-E 'pattern|$'
instead of-e
option.always
color option is useful to highlight multiple terms in different color, see stackoverflow.com/questions/172360... for exampleFor those interested in detailed learning of
GNU grep
andripgrep
, I have a book on that: github.com/learnbyexample/learn_gn... (I had a free offer running, but that ended yesterday, bad timing)Very helpful, thanks! I appreciate the input from someone who literally wrote the book.
The —always tip is especially good, because I was not sure that there was ever a good reason for that option. The -e choice of syntax was deliberate, as I think it gives an ever so slight readability boost over the more opaque regex syntax for showing separate patterns, but showing folks that the extended regex flag is available is a good tip. Thanks again!