Hi Paul, Thanks for your reply. It seems that trying to simplify my issue seems to have backfired. While your answer does indeed work for my simplified example it doesn't appear to be so with the un-simplified problem.
The required pattern matching is any line starting with "abc" and ending with a "?". If this looks like an exam question, that's because it is. The professor believed the correct answer was "^abc.*$\?" while I believed that that was incorrect, and it should be "^abc.*\?$". Testing my answer and hers for correctness led me to find this seemingly erroneous behavior. Here is a transcript of the input file and patterns with single quotes, double quotes, and unquoted. I do realize unquoting your pattern is bad practice but it does appear to produce the correct output, which is something I also don't understand as the unquoted pattern should get passed as "^abc.*?$" or "^abc.*$?". dw@circe:~$ cat testfile abc;klj? abcasdf ab;kb; dw@circe:~$ grep '^abc.*$\?' testfile abc;klj? abcasdf dw@circe:~$ grep "^abc.*$\?" testfile abc;klj? abcasdf dw@circe:~$ grep ^abc.*$\? testfile dw@circe:~$ I did some further experimentation, and the problem may lie with the regexp itself. dw@circe:~$ grep "^abc.*\?$" testfile abc;klj? abcasdf dw@circe:~$ grep '^abc.*\?$' testfile abc;klj? abcasdf dw@circe:~$ grep ^abc.*\?$ testfile abc;klj? dw@circe:~$ Thanks again, Daniel Wilson On Thu, Mar 22, 2012 at 11:38 AM, Paul Eggert <[email protected]> wrote: > On 03/21/2012 08:16 PM, Dan wrote: > > Hello, > > > > I've noticed something strange when using grep. It has to do with a > > pattern similar to this one: "hello$world". > > My guess is that your shell is interpreting '$world' as the > empty string, usually. (Depends on what identifier you're > using, 'world' being just one.) Try using single quotes > rather than double. > -- ~~ Whatever happens, the sun's still gonna come up tomorrow ~~
