This script will remove all lines that start with # along with all comments.
Whatever file you choose I suggest you view first then execute
sed "/^\s*#/d;s/\s*#[^\"']*$//" /etc/dnsmasq.conf && sed '/^\s*$/d' /etc/dnsmasq.conf
sudo sed -i "/^\s*#/d;s/\s*#[^\"']*$//" /etc/dnsmasq.conf && sudo sed -i '/^\s*$/d' /etc/dnsmasq.conf