1

My gawk script isn't matching all potential results, it's only matching one of them..

Example -

script:

gawk -F: "FNR==NR{a[$2]=$1;next} $1 in a{print a[$1] FS $2}" username.email.txt email.phone.txt > username.phone.txt 

email.phone.txt - contains:

 email@email.com:phoneexample

username.email.txt - contains:

 user1:email@email.com
 user131:email@email.com

EXPECTED OUTPUT - should be:

 user1:phoneexample
 user131:phoneexample

instead it will only match 1 of the lines containing " email@email.com "

outputting -

 user131:email@email.com
1

You might be better off when reversing files and fields:

awk -F: 'FNR==NR{a[$1]=$2;next} $2 in a{print $1 FS a[$2]}' email.phone.txt username.email.txt
user1:phoneexample
user131:phoneexample

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.