0
votes

I have two files file1 and file2. some of the names in file2 are not in file1. I would like to add that names in file1.

file1

anna         14/2   =   7.0
alex         23/6   =   3.8
deffy        27/3   =   9.0
hobert       24/9   =   2.7

file2

anna
alex
benny
cathar
deffy
hobbert
sam

My desired output is shown below.

anna         14/2   =   7.0
alex         23/6   =   3.8
benny        0/0    =   0
cathar       0/0    =   0 
deffy        27/3   =   9.0
hobert       24/9   =   2.7
sam          0/0    =   0

your help would be appreciated!

2

2 Answers

2
votes
kent$  awk 'NR==FNR{a[$1]=$0;next}a[$0]{print a[$0];next}{print $1,"0/0 = 0"} ' f1 f2|column -t
anna     14/2  =  7.0
alex     23/6  =  3.8
benny    0/0   =  0
cathar   0/0   =  0
deffy    27/3  =  9.0
hobbert  0/0   =  0
sam      0/0   =  0
1
votes

Another awk,

awk 'NR==FNR{a[$1]=$0;next} {$0=($1 in a )?a[$1]:$0" 0/0 = 0"}1' file1 file2