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 protected]:012345
[email protected]:912345

Example of name.email.txt:

Charles:[email protected]
Erica:[email protected]

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

1 Answer 1

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, 2019 at 3:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .