How do I get the public key of a pem file?

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 

JazzCat's answer works. small addition: if your permissions are vague on .pem file, ssh-keygen will generate empty .pub file.

if you see any complains on terminal about private key too open, try to narrow it using chmod 400 private.pem and retry above command.

ps: sorry I don't have permissions to add a comment instead of answer.