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 tried something like wc -l | grep vi file1
How is the proper way to do it ?
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 tried something like wc -l | grep vi file1
How is the proper way to do it ?
Your code nearly works, you just have to change
wc -l | grep vi file1
to
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.
Why not using pgrep
:
pgrep "^vi" | wc -l
pgrep man page:
SYNOPSIS
pgrep [options] pattern
DESCRIPTION
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
vi
is presented at any position.
Apr 9, 2014 at 9:10