Linux riddle given to me by my teacher. Having problems
The famous quote from Shakespeare's Hamlet, "To be or not to be," can be represented by the following regular expression:
(2b | [^b] {2}) IF you used this expression when searching a text file using grep and egrep command, what would be displayed? example- (egrep " 2b | [^b] {2})" myfile.txt WHY does it display what it does, that is the question!? can someone help me figure this out. Thank you |
What do you not understand?
Have you tried using it on a file to see what is displayed? |
Quote:
Per the LQ Rules, don't just post verbatim homework questions and ask for them to be answered. We're happy to HELP, but will not do your homework for you. |
Yes I tried it and it puts me into the file that im testing it on. It just shows a flashing cursor under the command I typed. It doesn't do anything else. What is it suppose to show me and why did it do that.
|
I have used my text book and google to look up each individual expression and what they do. For some reason when I type in that command it takes me to a > and displays nothing else. Ive used different commands at the > to try to navigate my file or to exit my file however it does nothing to the file. That's what im confused about. It does nothing and lol I think I just answered my question. Thanks for letting me post. I promise I did my homework on it but just couldn't figure it out. But typing all this I think I know what shes was doing. lol thanks all.
|
If you're getting the > prompt on the command line then the chances are that you've mucked up the quotation marks. Make sure you have matching open and close quotes.
P.S. Quote:
And thinking about it, that can be simplified to egrep "[^b]b|b[^b]" |
hmmm ... not so sure GazL ... not 2 b's does not imply that there is at least 1 b, which your solution does?
At OP, I would place single quotes around the regex so the shell also doesn't interpret anything ... not so much an issue here but I have found it a good habit for when you start using asterisks or question marks :) |
Quote:
Let's have another go: echo -e "2b\nbb\nab\nba\naa"| egrep "[^b].|.[^b]" # '2b' or not two 'b's. The teacher's version works out as " '2b' or two not 'b's " though which isn't Shakespeare either ;). |
All times are GMT -5. The time now is 05:29 AM. |