|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 (permalink) |
|
Messages: n/a
Hébergeur: |
I have some problems with grep and BRE (Basic Regular Expressions).
According to my documentation, a caret which is not the first character in a BRE matches a literal caret. The following command should find all lines containing "xx^x": grep "xx^x" But it doesn't match lines containing "xx^x". Whereas grep ".x^x" works fine. It matches "xx^x" Could somebody explain to me why the first command isn't working as expected. I'm using grep (GNU grep) 2.5.1 Thanks for your Daniel Mentz |
|
|
|
#2 (permalink) |
|
Messages: n/a
Hébergeur: |
On Mon, 21 Aug 2006 17:00:09 +0200, Daniel Mentz
<usenet@fire-of-desire.de> wrote: > I have some problems with grep and BRE (Basic Regular Expressions). > According to my documentation, a caret which is not the first character in > a BRE matches a literal caret. > > The following command should find all lines containing "xx^x": > grep "xx^x" > > But it doesn't match lines containing "xx^x". > > Whereas > grep ".x^x" > works fine. It matches "xx^x" > > Could somebody explain to me why the first command isn't working as > expected. > I'm using grep (GNU grep) 2.5.1 > It looks to me like you have discovered a bug. xx\^x will also work. -- We have nowhere else to go... this is all we have. -- Margaret Mead |
|
|
|
#3 (permalink) |
|
Messages: n/a
Hébergeur: |
On Mon, 21 Aug 2006 11:22:20 -0400, Bill Marcum wrote:
> On Mon, 21 Aug 2006 17:00:09 +0200, Daniel Mentz > <usenet@fire-of-desire.de> wrote: >> The following command should find all lines containing "xx^x": >> grep "xx^x" >> But it doesn't match lines containing "xx^x". > It looks to me like you have discovered a bug. xx\^x will also work. Thanks for your reply. I submitted a bug report on http://savannah.gnu.org/ I also tried it on a Solaris box and it works there. |
|
|
|
#4 (permalink) |
|
Messages: n/a
Hébergeur: |
Daniel Mentz wrote:
> I have some problems with grep and BRE (Basic Regular Expressions). > According to my documentation, a caret which is not the first character in > a BRE matches a literal caret. > > The following command should find all lines containing "xx^x": > grep "xx^x" > > But it doesn't match lines containing "xx^x". > > Whereas > grep ".x^x" > works fine. It matches "xx^x" > > Could somebody explain to me why the first command isn't working as > expected. > I'm using grep (GNU grep) 2.5.1 > > Thanks for your > Daniel Mentz Using GNU grep 2.5.1: syscjm@ayato:~$ grep "xx^x" << EOF > xxx^ > ^xxxx > xxaxx^xb > xx^xstuff > now is the time > for all xx^x > EOF xxaxx^xb xx^xstuff for all xx^x syscjm@ayato:~$ Certainly seems to work fine to me. Perhaps you could be more specific about your problems. Chris Mattern |
|
|
|
#5 (permalink) |
|
Messages: n/a
Hébergeur: |
On 2006-08-21, Chris Mattern wrote:
> Daniel Mentz wrote: >> I have some problems with grep and BRE (Basic Regular Expressions). >> According to my documentation, a caret which is not the first character in >> a BRE matches a literal caret. >> >> The following command should find all lines containing "xx^x": >> grep "xx^x" >> >> But it doesn't match lines containing "xx^x". >> >> Whereas >> grep ".x^x" >> works fine. It matches "xx^x" >> >> Could somebody explain to me why the first command isn't working as >> expected. >> I'm using grep (GNU grep) 2.5.1 >> >> Thanks for your >> Daniel Mentz > > Using GNU grep 2.5.1: > > syscjm@ayato:~$ grep "xx^x" << EOF > > xxx^ > > ^xxxx > > xxaxx^xb > > xx^xstuff > > now is the time > > for all xx^x > > EOF > xxaxx^xb > xx^xstuff > for all xx^x > syscjm@ayato:~$ > > > Certainly seems to work fine to me. Perhaps you could be > more specific about your problems. I see the same problem: $ grep --version grep (GNU grep) 2.5.1 $ grep "xx^x" << EOF > xxx^ > ^xxxx > xxaxx^xb > xx^xstuff > now is the time > for all xx^x > EOF $ -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#6 (permalink) |
|
Messages: n/a
Hébergeur: |
On Mon, 21 Aug 2006 14:18:26 -0400, Chris Mattern wrote:
> Daniel Mentz wrote: >> The following command should find all lines containing "xx^x": >> grep "xx^x" >> >> But it doesn't match lines containing "xx^x". >> I'm using grep (GNU grep) 2.5.1 > Using GNU grep 2.5.1: > > syscjm@ayato:~$ grep "xx^x" << EOF > > xxx^ > > ^xxxx > > xxaxx^xb > > xx^xstuff > > now is the time > > for all xx^x > > EOF > xxaxx^xb > xx^xstuff > for all xx^x > syscjm@ayato:~$ > > > Certainly seems to work fine to me. Perhaps you could be > more specific about your problems. I tried the command you provided on three different machines and I get a different output (no output at all). Would you mind trying it on another machine as well? I also downloaded a vanilla version of GNU grep 2.5.1 and I'm getting the same result. [mentz@baobab src]$ ./grep "xx^x" << EOF > xx^x > EOF [mentz@baobab src]$ Thanks Daniel Mentz |
|
|
|
#7 (permalink) |
|
Messages: n/a
Hébergeur: |
Daniel Mentz wrote:
> On Mon, 21 Aug 2006 14:18:26 -0400, Chris Mattern wrote: > > >>Daniel Mentz wrote: >> >>>The following command should find all lines containing "xx^x": >>>grep "xx^x" >>> >>>But it doesn't match lines containing "xx^x". > > >>>I'm using grep (GNU grep) 2.5.1 >> >>Using GNU grep 2.5.1: >> >>syscjm@ayato:~$ grep "xx^x" << EOF >> > xxx^ >> > ^xxxx >> > xxaxx^xb >> > xx^xstuff >> > now is the time >> > for all xx^x >> > EOF >>xxaxx^xb >>xx^xstuff >>for all xx^x >>syscjm@ayato:~$ >> >> >>Certainly seems to work fine to me. Perhaps you could be >>more specific about your problems. > > > I tried the command you provided on three different machines and I get a > different output (no output at all). Would you mind trying it on another > machine as well? > > I also downloaded a vanilla version of GNU grep 2.5.1 and I'm getting the > same result. > > [mentz@baobab src]$ ./grep "xx^x" << EOF > >>xx^x >>EOF > > [mentz@baobab src]$ > My test above was done on a Debian box with a fairly up-to-date Etch distribution, using GNU grep 2.5.1 and GNU bash 3.1.14(1)-release. A test on a Solaris 10 box with up-to-date patches, using Solaris grep (both /usr/bin/grep and /usr/xpg4/bin/grep) and ksh (M-11/16/88i) produced the same successful results. At the moment, to me, it looks to me like a bug in GNU grep that Debian patched. Chris Mattern |
|
|
|
#8 (permalink) |
|
Messages: n/a
Hébergeur: |
Chris Mattern wrote: > Daniel Mentz wrote: > > On Mon, 21 Aug 2006 14:18:26 -0400, Chris Mattern wrote: > > > > > >>Daniel Mentz wrote: > >> > >>>The following command should find all lines containing "xx^x": > >>>grep "xx^x" > >>> > >>>But it doesn't match lines containing "xx^x". > > > > > >>>I'm using grep (GNU grep) 2.5.1 > >> > >>Using GNU grep 2.5.1: > >> > >>syscjm@ayato:~$ grep "xx^x" << EOF > >> > xxx^ > >> > ^xxxx > >> > xxaxx^xb > >> > xx^xstuff > >> > now is the time > >> > for all xx^x > >> > EOF > >>xxaxx^xb > >>xx^xstuff > >>for all xx^x > >>syscjm@ayato:~$ > >> > >> > >>Certainly seems to work fine to me. Perhaps you could be > >>more specific about your problems. > > > > > > I tried the command you provided on three different machines and I get a > > different output (no output at all). Would you mind trying it on another > > machine as well? > > > > I also downloaded a vanilla version of GNU grep 2.5.1 and I'm getting the > > same result. > > > > [mentz@baobab src]$ ./grep "xx^x" << EOF > > > >>xx^x > >>EOF > > > > [mentz@baobab src]$ > > > > My test above was done on a Debian box with a fairly up-to-date Etch > distribution, using GNU grep 2.5.1 and GNU bash 3.1.14(1)-release. > A test on a Solaris 10 box with up-to-date patches, using Solaris grep > (both /usr/bin/grep and /usr/xpg4/bin/grep) and ksh (M-11/16/88i) > produced the same successful results. At the moment, to me, it looks > to me like a bug in GNU grep that Debian patched. > > > Chris Mattern On a Aix 4.3.3 ksh: just FYI, $ more go echo "A" grep "xx^x" << EOF xxx^ ^xxxx xxaxx^xb xx^xsstuff now is the time for all xx^x EOF $ $ ksh go A xxaxx^xb xx^xsstuff for all xx^x JB |
|
![]() |
| Outils de la discussion | |
|
|