Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Ignore grep command self-match' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Ignore grep command self-match
Authored by: kholburn on Aug 08, '05 01:15:36AM
Here's my preferred ps command. Note that the complicated method for not using grep -v grep doesn't really work here because I like to see the header line so I use egrep to grab that (egrep "PID|$1").

myps () 
{ 
    if [ $# -gt 0 ]; then
        ps -awwwxo "pid ppid %cpu %mem user command" | egrep "PID|$1" | grep -v grep;
    else
        ps -awwwxo "pid ppid %cpu %mem user command";
    fi
}
To use the [m]ethod from sweth's post you would have to say this:

myps () 
{ 
  if [ $# -gt 0 ]; then
    ENDING="${1#?}"
    REST="${1%${ENDING}}"
    ps -awwwxo "pid ppid %cpu %mem user command" | egrep "PID|[$REST]$ENDING"
  else
    ps -awwwxo "pid ppid %cpu %mem user command";
  fi
}

Is it worth it?

[ Reply to This | # ]