Piping To Grep Is Giving Too Many Results

I'm trying to check whether a particular service is running via a Linux terminal, and the following command doesn't seem to be filtering the results as expected. Not sure what I'm doing wrong...

service --status-all | grep subversion

This produces several lines of output, including, for example,

 [ ? ] Networking

I'm not sure why this is happening, since the string "subversion" is not contained within the above line...


You should use:

service --status-all |& grep subversion

Because the services without a status ([ ? ]) are sent to stderr, which is not pipelined to grep (and then it is printed on your terminal regardless).

|& sends stderr to stdout so grep is able to filter it.

Try this and redirect stderr (2) to stdout (1):

service --status-all 2>&1 | grep subversion

Need Your Help

search multiple keywords recursively in a folder path

bash awk sed grep

I have a text file which contains multiple keywords one on each line for e.g.

How to add ANY language in app description on AppStore? Tremendous impact on downloads!

iphone localization app-store

By submitting my application when I want to create application description in my national language (SLOVAKIAN) there's no choice to do so on Localization tab. There's only main languages: French, G...