0

I'm having a issue with cross referencing data using gawk, when I use:

gawk -F: 'FNR==NR{a[$1]=$2;next} $2 in a{print $1 FS a[$2]}' email.phone.txt name.email.txt > name.phone.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

Expected output

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

However it only outputs the last matching phone using that email, so it will only output:

Charles:912345
Erica:912345

and dismiss the first phone used with that email..

0

GNU awk (gawk) --but not regular awk-- supports true multi-dimensional arrays, and you could use that:

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
1
  • Thanks for your help, fixed my issue! :) – user351531 May 6 '19 at 3:10

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.