I have this in my command history:
280 ls -l | egrep -v '^d'
348 ls -l | egrep '^d'
375 git help ls-tree
376 git ls-tree
377 git ls-tree HEAD
378 git ls-tree HEAD^
379 git ls-tree HEAD system
380 git ls-tree HEAD system/
381 git ls-tree HEAD^ system/
460 ls
463 ls
464 ls /*
465 ls */
466 ls -d */
468 ls -d */
469 ls -d *
I can list all commands that end with /
like this:
history | egrep "/$"
But if I want to list all commands that start with ls
, and I type this:
history | egrep "^\s*\d*\s*ls"
It returns nothing.
However, if I the output the text to a file and copy the output to regex101.com, then this regex correctly finds all commands that start with ls
.
Is there some other variable I need to use other than \s
to identify whitespace in the output with egrep?
\d
in ERE. You'll have to use GNU grep with PCRE-P
or use[[:digit:]]
– muru Aug 05 '20 at 09:01history | grep -P "^\s*\d*\s*ls"
worked. – Edward Tanguay Aug 05 '20 at 09:24