The Smith-Purcell effect, observed when an electron beam passes in the vicinity of a periodic structure, is a promising platform for the generation of electromagnetic radiation in previously unreachable spectral ranges. However, most of the studies of this radiation were performed on simple periodic gratings, whose radiation spectrum exhibits a single peak and its higher harmonics predicted by a well-established dispersion relation. Here, we propose a method to shape the spatial and spectral far-field distribution of the radiation using complex periodic and aperiodic gratings. We show, theoretically and experimentally, that engineering multiple peak spectra with controlled widths located at desired wavelengths is achievable using Smith-Purcell radiation. Our method opens the way to free-electron-driven sources with tailored angular and spectral responses, and gives rise to focusing functionality for spectral ranges where lenses are unavailable or inefficient.