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

link|improve this question

feedback

1 Answer

up vote 14 down vote accepted

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)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.