Regex, but without

Michael Hipp Michael at Hipp.com
Tue Jan 29 13:06:18 PST 2008


Brad De Vries wrote:
> On Jan 29, 2008 9:37 AM, Michael Hipp <Michael at hipp.com> wrote:
>> I'm not a very deep expert on regular expressions, and I can't seem to
>> find the answer in my trusty copy of 'Mastering Regular Expressions'.
>>
>> I want to find all instances of 'python' running for a given user so I
>> do this:
>>
>> $ ps -f -U michael | grep python
>> michael  24638 24618  0 08:31 pts/0    00:00:00 python
>> michael  24665 24643  0 08:32 pts/1    00:00:00 grep python
>>
>> But I get that hanger-on in my grep command. I can easily get rid of
>> that second line by stringing another grep after it, but there ought to
>> be a way to do it with only one regex.
>>
>> So I need a regex that will find every line with 'python' on it but not
>> 'grep'.
>>
>> Any help?
>>
>> Michael
> 
> Michael, you can try extending what you're looking for in order to
> remove the lines you don't want to see.  For example:
>      ps -f -U michael | grep "[0-9] python"
> 
> This will search for any number, zero through nine, followed by a
> space, followed by "python."

Thanks, Brad. That should work as it looks like the format always puts a 
number there.

Thanks,
Michael



More information about the Linux-users mailing list