Copy the public key to clipboard.
Linux
ssh-keygen -f private.pem -y | xclip
MacOS
ssh-keygen -f private.pem -y | pbcopy
Save to file
ssh-keygen -f private.pem -y > public.pub
Note that if your permissions are vague on the .pem file, then ssh-keygen will generate an empty .pub file.
You can usually fix this with:
chmod 400 private.pem