1
When i use 'ps', 'egrep' and 'wc' command to count number of processes, it gives me wrong value. I am running the command in 'Solaris 9' machine. Please assist in understanding the issue.
MyServer $ ps -fu root | egrep -v 'bash|ksh|ssh|ef|mailx|nohup|defunct|ps|sh|FND'
UID PID PPID C STIME TTY TIME CMD
root 16267 16171 0 Jan 28 ? 0:18 xyz
root 16269 16171 0 Jan 28 ? 0:07 abc
root 16268 16171 0 Jan 28 ? 0:07 ghi
MyServer $
Only 4 (3 processes + header) lines shown in output. But when i use below command it returns the output as 5
MyServer $ ps -fu root | egrep -v 'bash|ksh|ssh|ef|mailx|nohup|defunct|ps|sh|FND' | wc -l
5
On the otherhand, when I echo the output to a file and count the number of lines, it works perfectly normal.
MyServer $ ps -fu root | egrep -v 'bash|ksh|ssh|ef|mailx|nohup|defunct|ps|sh|FND' >temp && cat temp | wc -l
4
1Can you pipe the first example to
hexdump -Cv
and give the results? – iBug – 2017-02-04T11:44:01.263What is the output of
alias egrep
? – janos – 2017-02-04T12:54:33.863@iBug Unfortunately hexdump is not availble in my server.
bash: hexdump: command not found
– Jass – 2017-02-05T01:40:29.983@janos
MyServer $ alias egrep bash: alias:
egrep' not found` – Jass – 2017-02-05T01:42:15.4401If available, install the package
bsdmainutils
from your package provider. Thehexdump
should be available. Or you can usebusybox
instead. – iBug – 2017-02-05T04:27:19.797The 'wc' command was showing up on another line in the output, that wasn't showing up in the redirect. – Nevin Williams – 2017-02-08T03:58:16.907