Thursday, March 24, 2011

use "grep" command to find txt files containing telephone number.

use "grep" command to find txt files containing telephone number.
telephone number format could be:
"***-*******"
"**********"
"*** *******"
"***-***-****"

How to write it?

numbers are 3 digits (\d{3}), space or dash [\s-], 3 digits (\d{3}), space or dash [\s-], 4 digits (\d{4}).


grep '\d{3}[\s\-]{0,1}\d{3}[\s\-]{0,1}\d{4}' infile.txt

No comments:

Post a Comment