grep with regex for phone number

后端 未结 11 2148
盖世英雄少女心
盖世英雄少女心 2020-12-04 22:39

I would like to get the phone numbers from a file. I know the numbers have different forms, I can handle for a single one, but don\'t know how to get a uniform regex. For ex

11条回答
  •  青春惊慌失措
    2020-12-04 23:09

    I got this:

    debian:tmp$ cat p.txt
    333-444-5555
    (333)333-6666
    123 456 7890
    1234567890
    debian:tmp$ egrep '\(?[0-9]{3}[ )-]?[0-9]{3}[ -]?[0-9]{4}' p.txt
    333-444-5555
    (333)333-6666
    123 456 7890
    1234567890
    debian:tmp$ egrep --version
    GNU grep 2.5.3
    
    Copyright (C) 1988, 1992-2002, 2004, 2005  Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    debian:tmp$
    

提交回复
热议问题