On Fri, Feb 25, 2000 at 10:54:17AM +0000, David Boyce wrote:
>>>>>>>>Double quoted text comes from [EMAIL PROTECTED]
> >Ok. I'm kinda stumped here, maybe someone knows...
> >
> >I made this file because ? seems to work oddly in sed.
> >--begin--
> >#matchme
> >matchme
> >#?matchme
> >--end--
> >if I do:
> >
> >sed -n 's/^#?matchme$/&/p'  or
> >egrep '^#\?matchme$' or
> >gawk -F'\n' '{if ($1 ~ /^#\?matchme$/) print;}'
> >
> >I get
> >#?matchme
> >
> >but if I do
> >sed -n 's/^#\?matchme$/&/p' or
> >egrep '^#?matchme' or
> >gawk -F'\n' '{if ($1 ~ /^#?matchme$/) print;}'
> >
> >I get
> >#matchme
> >matchme
> 
> You seem to have switched your escaped/unescaped sed commands, but it
> makes no difference in this case.
        I realize this. This was the problem I was having, and the reason
        I wrote the email. The question I had asked was, why does escaping
        work backwards in sed? 
> 
> I'm not sure I believe this second result for sed.  Oh well.
        Do you have a unix box around with GNU sed? Try it.
        Other than that, all I can say is I get the following results on 
        linux/sed 3.02 and hpux/sed 2.04:

Script started on Fri Feb 25 07:19:41 2000
[noop@celine]$cat file
#matchme
#?matchme
matchme
[noop@celine]$sed -n 's/^#\?matchme$/&/p' file
#matchme
matchme
[noop@celine]$sed --version
GNU sed version 3.02

Copyright (C) 1998 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
[noop@celine]$exit

Script done on Fri Feb 25 07:22:21 2000

        If sed hadn't matched it when I escaped the ?, I wouldn't have
        a problem.. I would have figured out that sed didn't support ?
        but my confusion stemmed from the fact the \? in sed acted like ?
        in egrep and awk.

        I guess it's another one of those d*mn gnuisms, which while useful
        make it tricky to write portable scripts if I get into the habit
        of using the extensions.
> 
> An unescaped ? is not a special character in sed, whereas in egrep and
> gawk it means zero or one of the previous character/RE).  That's why
> egrep and gawk print two lines.
>
        Thank you. It's this whole Basic Regular Expression versus
        Extended Regular Expression thing. I hadn't realized there 
        were two kinds. 
> However, you may be interested to know that you don't have to do the
> substitute to get sed to print out matching lines.
> 
> sed -n '/^#?matchme$/p'
> 
> which does not require textual manipulation and therefore should be more
> efficient.
> 
        sweet. I'll remember to use that.
        thanks again.

greg
-- 
this is not here

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs

Reply via email to