I want to compute the HMAC of file A.txt and put it into file A_hmac.txt. I use openss library, now I have:

openssl dgst -hmac "myHmacKey" -out A_hmac.txt A.txt

The output, inside A_hmac.txt, is:

HMAC-SHA256(A.txt)= 5aaee07459e341752...

How do I manage to have as output only:




Though, Not an OpenSSL solution, In Linux;

openssl dgst -hmac "myHmacKey" output.txt


HMAC-SHA256(output.txt)= 3bcf4e453c9b8008035e7f5e0ea84f092f795fc602bb3adccfde0f916dd565b2

The using the cut on the space char

openssl dgst -hmac "myHmacKey"  output.txt  | rev | cut   -d' ' -f1 | rev > myHmacKey

Then cat myHmacKey outputs


  • Thanks, this will work for me because my file has no space in their name. However, I will keep my question alive in order to cover spaced names, just for academy. – Francesco Pagani Jan 12 at 12:46
  • The original answer, check the history, was not considering the space. Later I've thought that the filenames can contain spaces so I've updated the answer to deal with the two cases. – kelalaka Jan 12 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.