X-ray scattering studies of charge density waves in cuprate and pnictide superconductors