开发者

Suppress Non-Matching Lines in Grep [closed]

开发者 https://www.devze.com 2023-04-09 16:25 出处:网络
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. 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

精彩评论

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