1 Answer
1

You can change the amount of surrounding lines grep outputs (called the "context") with options -C [num] or --context=[num].

Usually, the default option for grep is to print no context, so the command you used should be fine. You can force it to show only matching lines by service --status-all | grep + -C 0.

To exclude matching lines, use -v or --invert-match. So, you can pipe the original command through | grep -v '[ ?' | grep -v '[ -' to get rid of lines with - or ? as their status. You can also combine multiple match strings by using escaped "or" (the pipe symbol), like grep -v '[ ?\|[ -'.

However, as service for some reason directs its output to stderr instead of the normal stdout, the output streams need to be combined with |& for the grep to work properly. So, the working command here would be service --status-all |& grep +.