Trying to use file1 which is the actual counts in $2 associated with each $1 entry. The total of each $1 is in file2 with the total in $3 . So when there is a match between $1 in file1 with $1 in file2 , then the % is calculated using the $2 value of file1 and $3 value of file2 . Thank you :).
The standard way to print a percent sign character in a printf format string (in C, in the printf utility, and in awk ) is with %% . Some versions of awk will let you get by with:
awk 'FNR==NR{A[$1]=$2;next} $1 in A{printf "%s %.1f%\n",$1, A[$1]/$3*100}' file1 file2
Others will give you a diagnostic similar to:
awk: weird printf conversion %
input record number 1, file2
source line number 1
awk: not enough args in printf(%.1f%
)
input record number 1, file2
source line number 1
awk 'FNR==NR{A[$1]=$2;next} $1 in A{printf "%s %.1f%%\n",$1, A[$1]/$3*100}' file1 file2