Mahendra Seth
Mahendra Seth

Reputation: 5

i want to match a number of any length in awk with pattern match

i have a number which i want to do percentile match and want the correct number in front of that with awk

Table 1 
    mobile
    9594047891
    9895943283
    9967545384
    9594028790


Table 2 
    display
    4047891
    95943283
    545384
    28790


out put needed      
    display Output
    404789  9594047891
    95943283    9895943283
    545384  9967545384
    28790   9594028790

It will be of great help if any awk specialist can solve this

i am trying to match the number which is of 10 digit with the number which is less than 10 digit

Upvotes: -3

Views: 73

Answers (1)

Fravadona
Fravadona

Reputation: 17290

It seems like the short number matches the end of the long one, so you can do something like this:

awk '
    FNR == 1 { next }      # too lazy to handle the headers
    FNR == NR {
        longPhoneNumber[$1]
        next
    }
    {
        for (lpn in longPhoneNumber)
            if (lpn ~ $1"$") {
                print lpn, $1
                break
            }
    }
' Table1 Table2
9594047891 4047891
9895943283 95943283
9967545384 545384
9594028790 28790

Upvotes: 1

Related Questions