Greg Olszewski writes:
>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'm not sure I believe this second result for sed. Oh well.
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.
However, you may be interested to know that you don't have to do the
substitute to get sed to print out matching lines.
Try:
sed -n '/^#?matchme$/p'
which does not require textual manipulation and therefore should be more
efficient.
David Boyce
[EMAIL PROTECTED]
--
David Boyce
MessagingDirect (UK) Ltd.
Tel: +44 20 8332 9091 Richmond, Surrey, ENGLAND
Email: [EMAIL PROTECTED] WWW: http://www.MessagingDirect.
com/
-
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