Re: Locate with exclude?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday, Feb 19th 2007 at 13:37 -0600, quoth Mikkel L. Ellertson:

=>Steve Searle wrote:
=>> Around 01:20am on Monday, February 19, 2007 (UK time), Jean-Rene David scrawled:
=>> 
=>>> Another, shorter, way to do the same:
=>>>
=>>> ps auxw | grep '[p]rocessName'
=>> 
=>> I like it, but can you explain why it works?
=>> 
=>Regular Expressions. The [ ] specify a range to match. In this case,
=>it only matched p so grep is looking for processName, and because
=>the grep command has [p]rocessName it does not match. You can do
=>things like "ls /dev/[sh]d*" will give a list of all sd and hd
=>entries in the /dev directory. There is a lot more to it, but this
=>gives you a small idea of the power of regular expressions.

If you don't mind me getting picky... 

Shell commandlines have no idea about regular expressions. They do however 
know about globbing which is still a powerful construct but nowhere near 
as powerful as what regular expressions can do.

Had the above example been a regex, it would have been written 
differently:

ls /dev/[sh]d.*

In the first case, "Expand to /dev/ followed by either an s or an h 
followed by a d followed by anything or possibly nothing."

In the second case, "Expand to /dev/ followed by either an s or an h 
followed by a d followed by any character which is allowed to repeat zero 
or more times.

Just so you don't either feel stupid or think I am ;-) right now, the 
example here is the worst possible to demonstrate the point because this 
glob doesn't need anything more than what a regex could provide. But 
suffice it to say that there is a huge difference.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux