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

Click here to return to the 'grep faster and more effectively than grep, using grep' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
grep faster and more effectively than grep, using grep
Authored by: sweth on May 24, '07 07:47:26PM

1) I'm a Unix geek, so I don't have any anti-Unix-hint prejudice, but this is so not a Mac OS X hint that it's kind of scary.

2) If you're going to submit a Unix geek hint, at least make it a legit one. Anyone who is using grep in any of the hints on this site is almost definitely using it in an interactive setting, and any Unix geek worth their salt would know that you shouldn't optimize until performance actually becomes an issue, and in an interactive invocation of grep, the overhead of spawing the new process more than outweighs the overhead of the regex match so the "optimization" doesn't buy you anything of value.

3) If performance really does matter, again, spawning the grep process is going to be the big hit; you can avoid that and usually get much better performance by using shell constructs to do the fixed-string match: echo "foo" | fgrep "oo" will almost always be slower than echo "foo" | while read LINE ; do case $LINE in "oo" ) echo $LINE ; esac ; done. But, again, that's almost never a necessary optimization unless you're looping over that statement hundreds of times, and then you should be using a more robust tool like perl anyways.

[ Reply to This | # ]
grep faster and more effectively than grep, using grep
Authored by: dzurn on May 25, '07 07:17:29AM

Mac OS X has *nix underpinnings, so Unix hints are incredibly valuable for some tasks. I'm using the hints on this site as a Mac (power) user who wants to harness what these tools can provide. Yes, we could obtain and read the entire BASH Reference Manual or scour through the scarcely-readable "sh(1)" man page, but *nix is not something we use for hours on end and have hardwired into our fingertips.

Second, your "faster" example doesn't work for me. I tried it in sh, csh, zsh and it never returns what is expected. The first example works and is much easier to understand, and so might get used in the future.

The whole reason for the hint was to show a way to avoid remembering and escaping all the regex characters when we just want to match a bit of text in some other task.

Please don't denigrate this hint on the basis that it's not fast enough. You can however go ahead and denigrate us because we have only so much time to deal with learning and remembering the huge body of *nix tools.

Mac OS X is a tool to get something else done, it's not an end in itself. Learning all the *nix conventions and optimizations is not first on my list of things to do.

Madness takes its toll.
Please have exact change.

[ Reply to This | # ]
grep faster and more effectively than grep, using grep
Authored by: sweth on May 25, '07 06:04:19PM

You need to learn to read better (which might explain why manpages are so baffling to you). I never said that the hint wasn't fast enough; I said that it was pointless, because the speed of an interactive invocation of grep is very rarely going to be functionally helped by the switch to fgrep, and if speed really were an issue, using fgrep would rarely be the best solution. I've seen literally hundreds of people over the years get caught up in trying to optimize things that don't need to be optimized, and in ways that don't really help them; all I was trying to do was prevent people from wasting their time on what is almost always a fruitless endeavor.

(I'll concede that for people not familiar with regular expressions, the ability to use fixed strings instead of regexes could make fgrep useful, but that's not what the hint claims to be showing people to do. And judging from the current rating of the hint, it would seem that I'm not alone in not thinking that this is not a great hint.)

[ Reply to This | # ]
grep faster and more effectively than grep, using grep
Authored by: baba on May 26, '07 05:17:13PM

dzurn is spot on.
And especially don't denigrate the hint using Valley Girl English: "...this is so not a Mac OS X hint..."

Heh. Do you happen to remember that line from The Last Emperor where Peter O'Toole's characater states "A gentleman always means what he says, and says what he means."? Once you get beyond the anachronism (by today's standards) that he pronounces the 'h' in 'what,' you can see he has a point.

Alack, maybe I am the anachronism here ....

[ Reply to This | # ]