0

What I want to do is print a command-help (viz. "ls --help") and grep the output for any specific word. Consider the following:

ls --help | grep 'F'

But what this does is just filter out the other useful help.

I am aware of -A, -B, -C options for grep, but I want a better solution.

Highlight console search output, while displaying entire command output

This link gives the basic usage of the command, but I want to have something like:

grep -E --color 'pattern' <<<SOME COMMAND HERE>>>

E.G: grep -E --color 'pattern' <ls --help>

Is it possible to do? Basically, grep the ls --help but also print the whole help doc.

0

I found the answer,

You can use Extended Grep like:

ls --help | egrep '<pattern>|'

Like- ls --help | egrep 'F|'

Notice the pipe at the end. Alternately, you can use grep -E

This answer was originally posted at: https://stackoverflow.com/a/28210153/2095777

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.