You can change the amount of surrounding lines
grep outputs (called the "context") with options
-C [num] or
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
--invert-match. So, you can pipe the original command through
| grep -v '[ ?' | grep -v '[ -' to get rid of lines with
? as their status. You can also combine multiple match strings by using escaped "or" (the pipe symbol), like
grep -v '[ ?\|[ -'.
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 +.