Append sha256 column to a file

Hi,

My file looks like below:

1    abc@xyz.com
2    klm@klm.com

There are two fields separated by tab.
i want to append a third field which will be the sha256 hash of the email address field.

Anyone have any solution?

Note: I have already tried with while read line .... but the performance is very poor.

Thanks,
Mihir Ray

Thanks,
Mihir Ray

You could use a perl script:

#!/usr/bin/perl
use Digest::SHA qw(sha256);

while (my $ln = <STDIN>) {
    my ($num, $email) = split(/\s+/, $ln);
    print $num, " ", $email," ", unpack("H*", sha256($email)), "\n";
}

Save as shline.pl, do chmod +x shline.pl and then run it like this:

$ ./shline.pl < emails.txt
1 abc@xyz.com ee278943de84e5d6243578ee1a1057bcce0e50daad9755f45dfa64b60b13bc5d
2 klm@klm.com 3d3228ccec60808cc70f3b4541991a28d828dcab225cf4d6a7be367eebbf2fba