Recently, I inadvertently deleted a whole lot of packages on my Linux distribution by deleting one specific package and then running sudo apt-get autoremove
. Here is how I reinstalled them automatically, after noticing I could not boot the X server up anymore:
awk '/Purge|Remove/ { gsub( /\([^()]*\)/, "" ); gsub(/ ,/, " ");sub(/Install:/,""); print}' /var/log/apt/history.log > repair.txt
sudo apt install $(cat repair.txt)
Hope this helps.