Is it possible to search and print only the matched pattern from grep. The default action is to print the whole line.

1 Answer 1


Yes. Use the -o option, e.g.,

$ echo 'hello wide world' | grep -o wide

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.