Can a doctor specialize in family medicine and then do a fellowship in infectious diseases?

No. Internal medicine and pediatrics both have infectious disease fellowships available after their primary training is completed. This is not available to those completing residencies in family practice.
Infectious disease. Usually not. If the plan is to do infectious disease fellowship, it would be better to do internal medicine residency.