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: al.cameron on Aug 09, '05 02:56:35PM
Note: the original hint specifically dealt with grep-ing for "literal strings" and then the discussion went off madly in all directions... :-)
However, this did result in a very useful generalization.

Using the word-boundary is a great modification to allow working with variables. Thanks!

If you combine the REs for the literal string "PID" and the function argument "$1", your function could reduce to:

myps () 
    ps -awwwxo "pid ppid %cpu %mem user command" | egrep "[P]ID|\b$1"
if you don't mind the extra egrep (which matches all lines) when there is no function argument.


[ Reply to This | # ]