[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Apparent bug in grep 2.5.1-31 from RHEL 3 and RHEL 4?

From: Pedro Freire
Subject: Apparent bug in grep 2.5.1-31 from RHEL 3 and RHEL 4?
Date: Fri, 6 Oct 2006 20:47:55 +0100

Dear sirs,

I teach computer science classes in Portugal, and today during one of my
"Unix Operating Systems" classes I stumbled onto what seems to be a grep

I create a test text file "p.txt" with:


Mobile phone numbers in Portugal are always 9 digits long and start with the
digit "9". I wanted a regular expression that would find valid portuguese
mobile phone numbers. I also wanted that the number could have the optional
separators "space" and "hifen" anywhere between the digits.

Under such terms, the first and third lines comply with "Portuguese mobile
phone numbers with separators".

The obvious command to show such lines would be something like:

        egrep '^9([ -]?[0-9]){8}$' p.txt

I gave my students the result when one of them, Danilo Silva, told me he had
created the test file I quote here, and it hadn't worked. As it is typical
with many students, I assumed the mistyped something and went to help him.
The truth is he hadn't mistyped anything and the behaviour of this
expression is mistifying. It returns the first and SECOND line of the
result, instead of the first and third!

Changing it to:

        egrep '^9(-?[0-9]){8}$' p.txt

will make it run fine, but even a simple

        egrep '^9([-]?[0-9]){8}$' p.txt

will fail. Assuming it could be the special "-" character that was confusing
the range "[]" construct, I tried:

        egrep '^9(a?[0-9]){8}$' p.txt

will make it run ok, returning only the first line as expected, but then

        egrep '^9([a]?[0-9]){8}$' p.txt

will retun the first and SECOND lines! AFAIK, there's no way this expression
could match ten numeric digits!

I can't explain this. Perhaps I'm missing something but I'd swear it's a

Please let me know.

Thank you,

Pedro Freire

reply via email to

[Prev in Thread] Current Thread [Next in Thread]