Skip to content Skip to sidebar Skip to footer

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... The co

Solution 1:

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 your desired output.

If the input is

rgf34 | 9 | 2015-07-20 | hello thisis 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 thisis my number
rgf35 | 10 | 2015-07-20 | my number :  can you check...

Post a Comment for "Python Remove Phone Numbers From String"