My table file example looks like that
Name1 xxxxx 34
Name1 xxxxx 37
Name2 aaaaa 59
Name2 xxxxx 90
Name4 Name3 12
Name file looks like that
Name1
Name2
Name3
Name4
I want awk to match Name1/2/3/4 from Name file to table file $1 and print sum of $3. If Name is not found print 0 - how can I do such if statement in awk?
What I already done:
for i in $(cat Name_file)
do
cat table | awk -v NAME="$i" '($1==NAME) {SUM+=$3} END {print NAME"\t"SUM}'
done
Gives output
Name1 71
Name2 149
Name3
Name4 12
It's almost perfect - I want to add 0 to Name3 to get such output
Name1 71
Name2 149
Name3 0
Name4 12
So much question is: How to add if not found do function in awk?