Suppress Non-Matching Lines in Grep [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_高级运维 Improve this questionRunning service --status-all | grep "firestarter"
in Ubuntu shows the entire output of service --status-all
with the text "firestarter" highlighted in red. How do you get grep to only show the line that contains the matched text, and hide everything else?
Maybe service --status-all
writes to stderr, not stdout? Then you can use
service --status-all 2>&1 | grep firestarter
You must have some weird env variables set. Try this:
service --status-all | `which grep` firestarter
Or:
service --status-all | /bin/grep firestarter
And show the output of env
and alias
if possible so we can see whats wrong with your grep
command.
For me, I have:
[ 13:55 jon@host ~ ]$ echo $GREP_OPTIONS
--color=always
You probably have something set there, and/or in GREP_COLOR
that is causing this.
if you don't want to use an alias, but the original command, you could try "\cmd". e.g.
service --status-all | \grep "firestarter"
精彩评论