COLUMNS=200 dpkg -l | awk '/^[hi]i/{print $2}' | xargs apt-get -y --reinstall install
or
dpkg --get-selections > packages
and later
dpkg --set-selections < packages && apt-get install