If you have either pcregrep
or pcre2grep
you can use the -o1
command-line flag to request that only capture group 1 is output. (Or change 1 to some other number if there are more captures in the regex.)
You can use the -oN
command more than once if you want to output more than one capture group.
As far as I know, grep -P
does not implement this extension. You'll find pcre2grep
in Debian/Ubuntu package pcre2-utils
. pcregrep
is in package pcregrep
.