with question about grep

the command to enter the count of the number of emacs processes by all user

when i enter
ps -Af | grep emacs | grep ssh | wc it give me 0

im kinda lost i dont know what to do is say that not it i try different things
You don't need the grep for ssh since you're looking for all users, that command would disclude any lines not including ssh. And I don't think that the ps -Af reports whether the user is an ssh user or not...

ps -Af | grep -i emacs | wc
Last edited on
Please note that you'll also get include the command "grep -i emacs" in the count.
Do you have command 'pgrep'? If yes:
pgrep -c emacs



Btw, the 'man grep' says that grep has option '-c':
ps -Af | grep -c -i emacs




In your original pipe the 'ps -Af' creates list FOO.
The first grep takes list FOO and creates a shorter list BAR, where each line contains 'emacs'.
The second grep takes list BAR and creates a shorter list GAZ, where each line contains 'ssh'.
Therefore, the GAZ has only the lines of FOO that have both 'emacs' and 'ssh'.
sorry for the late respond when i do
'ps -Af | grep -c -i emacs'
it gives me the hint use 'grep' to select lines containing 'ssh'
What gives a hint?

I don't think that neither ps nor grep should write to stderr, just to stdout. The pipe feeds all stdout of ps to grep and due to the -c, the only thing that grep writes out is an integer.
Topic archived. No new replies allowed.