开发者

Suppress Non-Matching Lines in Grep [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

开发者_高级运维 Improve this question

Running 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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜