awk compare two files and print all match and non match with repetition on both files -


i have two files

file1 1,david 22,jack 31,sharon 46,susan  file2  770,jackson 779,david 776,sharon 775,david 771,sharon 777,susan 

i want compare file2 matches in file 1
file2 can contain more 1 occurrence of same name in column 2
matches colum2 in file1
output need below

779,1 775,1 771,31 777,46 

have tried examples given stackoverflow not getting output

example

awk -f, 'nr==fnr{a[$1]=$2;}nr>fnr{if (a[$1]==$2)print $1,${a[$2]}' file1 file2 

you can without awk, sort , join only:

join -t , -1 2 -2 2 -o 2.1 1.1 <(sort -t , -k 2 file1) <(sort -t , -k 2 file2) #     ^    ^    ^    ^---- select fields display      ^    ^ #     |    |    '--------- field in common file2           |    | #     |    '-------------- field in common file1           |    | #     '------------------- field separator --------------------'    | #                          field used sort file -------------' 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -