10

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

0

1 Answer 1

18

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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