Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

First of all I save in a file all of the working processes.

ps -el > file1

My idea is to count the number of lines in file1 where vi is present.

I tryied something like wc -l | grep vi file1

How it\s the proper way to do it ?

share|improve this question
Could you please explain if you're looking for all VI processes (VI the text editor) or processes containing vi, to match not only vi or vim but services as well. Thanks –  Sylvain Pineau Apr 9 '14 at 9:20

2 Answers 2

up vote 1 down vote accepted

Your code nearly works, you just have to change

wc -l | grep vi file1


grep vi file1 | wc -l

The pipe operator uses the output of the program on the left as input for the program on the right.

share|improve this answer
only grepping for vi will match all serVIces... –  Sylvain Pineau Apr 9 '14 at 8:48

Why not using pgrep:

pgrep "^vi" | wc -l

pgrep man page:


   pgrep [options] pattern


   pgrep looks through the currently running processes and lists the process 
   IDs which matches the selection criteria to stdout.

EDIT: (Using the file):

ps aux > file1
awk '{ print $11 }' file1 | egrep '^vi' | wc -l
share|improve this answer
Thank you, but do you know how can I do it with the file? –  user253956 Apr 9 '14 at 8:44
I've updated my answer –  Sylvain Pineau Apr 9 '14 at 8:56
@SylvainPineau i think op want to display the lines where vi is presented at any position. –  Avinash Raj Apr 9 '14 at 9:10
Humm, in that case to match all "vi" patterns, remove the "^" before "^vi" so that you'll match not only vi, vim but also services like indicator-session-service, unity-webapps-service. –  Sylvain Pineau Apr 9 '14 at 9:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.