![]() |
Quote:
does: egrep 'foo|bar|baz' textfile work? |
Please don't tell me it's strange, let alone very strange! "Strange" seems to be my NMOO (normal mode of operation) with Unix. :p
This is what I get when I try egrep with the | and \|: Code:
% cat test.txt |
But that's *fine*! I think I see what's going on here: Doug backslashed his "|" symbols because he didn't quote the whole regular expression. That backslashing prevented the shell from thinking they were pipes (and thus chucking a fit about not being able to find the command on the right hand side of the first pipe, or maybe offering a strange substitution). Quoting your expression has the same effect: *egrep* gets to see the "|" symbols instead of the greedy old shell grabbing them in transit.
When you wrote above that your egrep worked *without quotes and without backslashes* it certainly was "interesting". But if you were quoting all the way, just invisibly in the post that's about 3 above this one, then the world is at peace. When you write % egrep 'ez\|x\|techhhh' test.txt you're asking for occurences of the literal text 'ez|x|techhhh'. In other words, you've "double-negativized" the "|" symbol, so that it's interpreted literally. I hope that's close, anyway. Seems to pass my tests! Cheers, Paul |
Ah, but that's not strange at all! (Strange is far from NMOD with Unix BTW).
Notice that stetner said: Code:
egrep foo\|bar\|baz textfileCode:
egrep 'foo\|bar\|baz' textfileCode:
egrep 'foo|bar|baz' textfile |
Ahhhh! Okay, the light just switched on. :) I didn't even notice the absence of the quotes in stetner's message. I just did a copy/paste from his message when writing mine so the absent quotes copied/pasted right along with it. Using quotes is just second nature to me (I've always used quotes when allowed, even if not required). I will be more watchful for the variations of quotes/absent quotes in the future.
Okay, mystery solved. Thanks! :) |
Vicki: I just have to confuse you a little bit more. If you had done your double quoting using grep instead of egrep, like:
Code:
grep 'foo\|bar\|baz' textfile |
greep is creepy. i prefer grap or grop, grup even.
|
Very mysterious and ooky, if you ask me. ;)
My only possible contribution to this thread: grep stands for General Regular Expression Parser, IIRC. Back to read and learn something mode. :cool: |
Quote:
Actually, I understood what you said. But I had no idea you could do that with grep (multiple search)! I thought you had to use egrep for a multiple search! I learn so many things from you guys! :) |
Vicki: With GNU grep there's actually no difference between greps and egreps regular expression engines. It's just the parsing of those "extended" features that are different. With grep you have to put a backslash in front of those operating characters to get them to act special, with egrep you don't. With egrep you have to put a backslash in front of those characters to switch their special meaning off, with grep you don't.
Craig: According to "Master Regular Expressions" by Jeffrey Friedl grep got it's name from a common operation in the ed editor: :g/Regular Expression/p Which can be read as Global Regular Expression Print and it was so poular that a standalone utility, grep, was created for it. I don't know what sources Friedl has for this particular info, but I find it more plausible than "General Regular Expression Parser". Because grep does so much more than just parse the regexp and even so, what's "general" about grep? And my suggestions for names to Paul's "egrep -i" alias are: griffin or grip. The last one is the Swedish word for griffin (which is a mythical creature combining the bodies of three animals). In Swedish grip is pronounced greep. :) |
kudos
not adding any tech info, but just wanted to extend a kudos to vicki for the investigative attitude that will turn any newbie into a guru in no time (well, actually, lots of time but eventually people starting thinking you can do magic [not that i would know personally])
if only we could replace all the "MS Word in 21 days" books/classes with a "How to approach computers" or "How to approach computer software" books/classes, geeks might actually start shutting up about "lusers" of the world. |
You just made my day! Thank you! :)
|
Quote:
Code:
% pwd |
Quote:
:g/reg exp/p to print out all lines with the reg exp in it. I will just go back to cleaning my dentures now..... :) |
My book says it's global...
Quote:
|
|
Code:
grepCheers... |
Quote:
Quote:
Cheers, Paul |
Quote:
|
| All times are GMT -5. The time now is 10:35 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.