Here's a simple Unix tip, inspired by a comment Rob made on a recent hint:

...When I ran ps ax | grep Dash ... (OK, technically, it found the grep, but that's because I'm too lazy to add it as an ignored match)...

You can use a simple regular expression, instead of adding another grep -v pipe element, to ignore the self-match when grep-ing for a literal string. That is, rather than this:

ps ax | grep Dash | grep -v grep

Use this:

ps ax | grep [D]ash

The regular expression (the D inside the square brackets) matches a character set which contains a single character (upper case D in this case) and the literal string "ash." So this grep can't self-match the original regular expression string, as it also includes the square brackets.

[robg adds: Yep, this is a simple tip, but since regular expressions are not something I know anything about, I appreciate the timesaver ... so I figured it was worth sharing with other relative Unix newcomers...]

To save a little time typing, simply create an "alias" for this command in your "~/.cshrc" file. For instance, I have an alias called "psg" (ps and grep) that omits the original grep from the process list (grep -v grep) and does a case-insensitive search:

alias psg 'ps -augxww | grep -v grep | grep -i'

Add that to your ".cshrc" file, type "source .cshrc" to read in the changes, and then type "psg server" to test it out.

One of the advantages of the original hint is that it avoids the second grep process in the pipeline. However, its form, which requires separating the first letter from the others, makes difficult to embed in an alias. This is why the other suggestions go back to the two-process pipeline.

However, the general principle is that the regular expression not match its invocation. Since the names of programs are always "words" in the regular expression sense, there is another way to use the basic principle of the original hint, but which allows easy use in an alias: explicitly match the word boundary using the \b regular expression substring. This results in a command

grep \\bDash

for the original example, and since it is trivial to precede any string with \b or \b depending on the quote level, this can be used easily in a shell function or script:

function psg () { ps ax | grep \\b$1 ; }

Note that this can't be an alias because "$1" expands to " $1" when aliases are expanded, with an added space that messes up the regular expression. But functions work fine.

When I was first trying to grasp regular expressions I found the O'reilly book to be *very* enlightening. It's not very thick and the information it contains has helped me in perl, php, javascript, and tons of terminal utilities. I highly recommend this book if you're interested in learning Regex syntax.