linux - How to use functions in bash? -


this question has answer here:

i have file has hashes of files against filename. example,

fb7e0a4408e46fd5573ffb9e73aec021a9dcf426235c0ccfc37d2f5e09a68a23 /path/to/some/file 237e0a4408e46fe3573f239e73aec021a9dcf426235c023fc37d2f5e09a68a12 /path/to/another/file ... , on... 

i need hash converted base64 encoded format.

so used combination of bash function , awk.

here wrote,

#!/bin/sh base64encode() {      $1 | openssl base64 -a } awk ' { t = base64encode $1; print t } ' file.txt 

but not seem work. i'm using hashdeep generate hash-list file , hashdeep not support base64 encoded output. why i'm using openssl.

any or tips regarding great!

edit:

the given answers work i'm having other issue seems.

usually cat filename | openssl dgst -sha256 | openssl base64 -a gives base64 encoded output filename file absoutely correct, , output hashdeep matched output cat filename | openssl dgst -sha256. so, thought of piping output obtained above step openssl base64 -a base64 output. but, still different values actual result.

although might suited separate question perhaps, still appreciate support on this.

awk only:

$ awk '{ c="echo " $1 "|openssl base64 -a"          c | getline r          print r }' file zmi3ztbhndqwogu0nmzkntu3m2zmyjllnznhzwmwmjfhowrjzjqynjiznwmwy2nmyzm3zdjmnwuwowe2ogeymwo= mjm3ztbhndqwogu0nmzlmzu3m2yymzllnznhzwmwmjfhowrjzjqynjiznwmwmjnmyzm3zdjmnwuwowe2ogexmgo= 

for tight one-liner version see @123's comment below.

... , @edmorton's super-tight (read: super-proof) version.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -