Is it possible for grep to output just the pattern match and not the whole line when it comes across a match? I know you can adjust the number of trailing or leading lines that are printed, but am yet to find anything that outputs just the pattern match.
What is the point of this?
grep -l lists the files the pattern is found in,, you already know what the pattern is (although not how many times but a -c would show you that).
Yours intrigued...
I'm guessing, but if it's a REGEX then there is logic. There could be multiple types of match possible, and you might want all of them. In Solaris for example to get a list of disks from format.
That said, standard grep is the wrong tool for this, sed could do it quite well or gnu grep or even awk.
$ cat t
google gooosdasasdgle derwsdfs
googsdfgle google sreogsds google gsdfsdfd
gooswoerjgle tosgsd towgsjsg googpoiwrwroiegle
$ sed '
s/^.*$/&\n/
:loop
s/^\n//
s/\(.*\)\( *goo.*gle *\)\(.*\)\n/\1\n\2/
t loop' t
google gooosdasasdgle
googsdfgle google google
gooswoerjgle googpoiwrwroiegle
The above command prints the words, which matches with the pattern "goo.*gle"