Python remove phone numbers from string

I have a text file that looks like this:

rgf34 | 9 | 2015-07-20 | hello this is my number 1234567890 
rgf35 | 10 | 2015-07-20 | my number : 123 - 456 -8888 can you check...

      

Columns are split into pipes and each new information is on a new line.

How can I go through the third column to remove all ph numbers? (all phone numbers are 10 digits and I don't know if they have brackets or dashes.)

I know I can use awk to just get the data in the third column, but I don't understand how to make the regex part:

This is the awk part:

awk -F "|" '{print $4}' myfile.txt

      

Expected Result:

rgf34 | 9 | 2015-07-20 | hello this is my number 
rgf35 | 10 | 2015-07-20 | my number : can you check...

      

+3


source to share


1 answer


If you put this in a.awk

BEGIN {
    FS = OFS = "|"
}
{
    sub(/[0-9].*[0-9]/, "", $4)
    print
}

      

and run

awk -f a.awk foo.txt

      

You will get the desired result.



If the entrance

rgf34 | 9 | 2015-07-20 | hello this is my number 1234567890 
rgf35 | 10 | 2015-07-20 | my number : 123 - 456 -8888 can you check...

      

The output will be

rgf34 | 9 | 2015-07-20 | hello this is my number
rgf35 | 10 | 2015-07-20 | my number :  can you check...

      

+4


source







All Articles