Linux – `grep`-like utility to match strings instead of lines

greplinuxregex

I'm using grep to extract lines that match a regular expression. How to get only the matches and not the whole line?

Best Answer

You can supply grep the -o option. Like such:

grep -o pattern file

(Hint: The mnemonic I use for this is: omit everything except match)

Related Question