Grep flags – the good stuff
11–20 of 53 posts
Re: Grep flags – the good stuff
#12Re: Grep flags – the good stuff
#13 -P, --perl-regexp
Interpret I as Perl-compatible regular
expressions (PCREs). This option is experimental when
combined with the -z (--null-data) option, and grep -P
may warn of unimplemented features.
As everything (python, Go, javascript, etc, etc) uses perl regexps now-a-days and I can never remember which things I need to escape for old gods regexp.Re: Grep flags – the good stuff
#14Living without those few "extensions" feels... empty
Re: Grep flags – the good stuff
#15very frequently I want to chain grep things... I lean on the "|" operator for this, e.g. cat hello | grep foo | grep bar and it seems verbose. any tips?
grep "foo.*bar" hello
Unfortunately, the basic grep syntax doesn't give you an easy way of specifying both orders, so that would have to be something like: grep -e "foo.*bar" -e "bar.*foo" hello
You can specify random order in a couple of different ways with Perl-compatible regexes, such as lookaheading the search terms from the end of line marker. But it's not as easy to read as it should be.Re: Grep flags – the good stuff
#16I think I have never used grep -r. I'm sure gnu grep has some way to specify which files to search, but why would I learn that syntax as well when I already know find, and exec works (exec + is much faster, but exec ; gets you the results too if your find lacks exec +).
Re: Grep flags – the good stuff
#17 sed -n 's/.*\(pattern\).*/\1/p'
it can instead simply be: grep -o 'pattern'
The -w flag is new to me today - excited to save still more keystrokes!Re: Grep flags – the good stuff
#18My favorite feature is: -P, --perl-regexp Interpret I as Perl-compatible regular expressions (PCREs). This option is experimental when combined with the -z (--null-data) option, and grep -P may warn of unimplemented features. As everything (python, Go, javascript, etc, etc) uses perl regexps now-a-days and I can never remember which things I need to escape for old gods regexp.
Re: Grep flags – the good stuff
#19I think I have never used grep -r. I'm sure gnu grep has some way to specify which files to search, but why would I learn that syntax as well when I already know find, and exec works (exec + is much faster, but exec ; gets you the results too if your find lacks exec +).
Check out ripgrep
[0] - https://github.com/BurntSushi/ripgrep#why-should-i-use-ripgr...
Re: Grep flags – the good stuff
#20very frequently I want to chain grep things... I lean on the "|" operator for this, e.g. cat hello | grep foo | grep bar and it seems verbose. any tips?
cat hello | sed -n '/foo/{ /bar/{ /baz/ p }}'