Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with grep command 2

Status
Not open for further replies.

starla0316

Programmer
Sep 8, 2003
15
SG
Hi!

I am trying to do a grep for one of our processes, but would like to know how not to include the command itself.

Ex. ps -ef|grep process
psoftfs 3164 1 4 03:46:45 ? 0:41 ./process INFILE=/directory/process
psoftfs 23269 8530 0 22:20:44 pts/5 0:00 grep process

As you can see, it returns both the output, and the command I issued. I am only interested in getting the particular process.

Also what would be the best command to count for the number of processes running (excluding the grep command itself).

thanks!
 
Include the first character of what you looking for in [].

eg

ps -ef |grep [n]fs
root 651 0 0 Nov 10 ? 0:00 nfskd

Martin
 
ps -ef | grep <process> | grep -v grep

add | wc -l at the end to get a count.
 
What I thought of was this:
ps -ef | grep -v grep | grep -c <process>
 
Martin99 has the most elegant solution. The [] pattern match will exclude your grep process. Although it doesn't handle variables.

--
Jack
 
Hi, For the second part of your question, the command "top" usually shows you exactly what is running without using grep, and it uses vi commands to run: j = forward a page, k = back a page, q = quit running top.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top