Subject: bug#18377: closed (Re: bug#18377: piping output through egrep -- escaping of "+" only needed sometimes. Why?)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 01 Sep 2014 08:07:02 +0000

Your bug report

#18377: piping output through egrep -- escaping of "+" only needed sometimes. Why?

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
18377: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18377
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#18377: piping output through egrep -- escaping of "+" only needed sometimes. Why?
From: Paul Eggert <[email-masked]>
To: [email-masked], [email-masked]
Date: Mon, 01 Sep 2014 01:05:51 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

[email-masked] wrote:
> Why do I need to escape the "+" in the last case, but not in the first?

Because "+" is a special character to egrep.  The pattern "libstdc++" is 
equivalent to the pattern "libstdcc*" which matches in the first case, 
whereas the pattern "libstdc++.so" is equivalent to the pattern 
"libstdcc*.so" which does not match in the last case.

Subject: piping output through egrep -- escaping of "+" only needed sometimes. Why?
From: [email-masked]
To: [email-masked]
Date: Sun, 31 Aug 2014 19:07:48 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi all,

I'm trying to pipe of output of a command through egrep.

If I do this

	ldconfig -p | egrep "libstdc++"
		libstdc++.so.6 (libc6,x86-64) => /usr/lib64/libstdc++.so.6
		libstdc++.so.6 (libc6) => /usr/lib/libstdc++.so.6

that *IS* the answer I expect.

But if I simply add a ".so" to the egrep target, it returns nothing

	ldconfig -p | egrep "libstdc++.so"
		(empty)

If I *escape* the two "+", it works again.

	ldconfig -p | egrep "libstdc\+\+.so"
		libstdc++.so.6 (libc6,x86-64) => /usr/lib64/libstdc++.so.6
		libstdc++.so.6 (libc6) => /usr/lib/libstdc++.so.6

Why do I need to escape the "+" in the last case, but not in the first?

Terry