0

So currently I have this script

gawk -F: '
    FNR==NR{a[$1][$2]=1;next}
    $2 in a{for(i in a[$2]) print $1 FS i}
' email.phone.txt name.email.txt

Example of email.phone contents:

Email@gmail.com:012345
Email@gmail.com:912345

Example of name.email.txt:

Charles:Email@gmail.com
Erica:Email@gmail.com

which will output

Charles:012345
Charles:912345
Erica:012345
Erica:912345

as you can see it currently examines 2 files and matches email.phone.txt first column against name.email.txt second column. If they match it will then output name.email.txt first column along with email.phone.txt second column using : as the seperator.

How can I do this to match partial strings?

Like so,

Example of email.phone contents:

Email@Email.com:012345

Example of name.email.txt:

Charles:Email@gm

expected output would now be

Charles:012345
Charles:912345
1
  • 2
    What do you mean by "partial string"? Email@gm is not a substring of Email@Email.com, nor is the other way round. Is this intended? If so, which part of the two strings is meant to be checked for matching? – fra-san Oct 19 '20 at 22:42
0

One solution is to read in the emails and then regex-match the telephone numbers on the fly:

$ cat email.txt
Charles:Charles@gm
Erica:Erica@gmail.com

$ cat tele.txt
Charles@gmail.com:012345
Erica@gmail.com:912345
$ awk -F ':' 'NR==FNR{ em[$1]=$2 } NR!=FNR{ for(i in em){
                if( $1 ~ em[i] ){ print i":"$2 } } }' email.txt tele.txt
Charles:012345
Erica:912345

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.