Extracting the GPG userid from the Public key file?

Use gpg --list-packets [filename] to list all data packets, then grep for user IDs. For example:

$ gpg --export 0xDED9B508F4E10DB2 | gpg --list-packets | Egrep '^:user ID packet'
:user ID packet: "John Doe <[email protected]>"

An alternative would be to use pgpdump

$ gpg --export 0xDED9B508F4E10DB2 | pgpdump | Egrep '^[[:space:]]*User ID'
    User ID - John Doe <[email protected]>

The following will emit the "username < email >" field from the UID packet, without requiring regexes:

$ gpg --with-colons --list-keys 0xDED9B508F4E10DB2 | awk -F: '$1=="uid" { print $10 }'
blah <a@b>