Re: grep: BRE with caret
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
|