It's because you don't just sha256 it, you sha256 it twice, then reverse the result!
$ clamd getrawtransaction 512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0 |
xxd -r -p | # convert hex to binary
sha256sum | # hash it
xxd -r -p | # convert hex to binary
sha256sum | # hash it
awk '{print $1}' | # keep just the hash: 01234567
rev | # reverse it: 76543210
sed -E 's/(.)(.)/\2\1/g' # switch adjacent bytes: 67452301
512f2e27b233eee9c28ac0f12a653ca1b6e1ef76b8214915d7865dda0b51dfc0
Edit: I learned this from https://en.bitcoin.it/wiki/Dump_format#General_note_about_hashes - and found that page by googling for 9a538906e6466ebd2617d321f71bc94e56056ce213d366773699e28158e00614, which is what Bitcoin gives when you hash a single 00 byte (which is what I got when I serialized an empty string).
Thanks again, Shorena, I just looked closer and I hadn't seen that dooglus had edited his post to find the answer---I had only seen the earlier version of his post which basically said he wasn't sure why it wasn't working. Cheers!
Oh yah, and massive thanks to dooglus for figuring it out and showing the example in exactly the environment I was looking for.