Append sha256 column to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append sha256 column to a file
# 1  
Old 11-11-2013
Display Append sha256 column to a file

Hi,

My file looks like below:
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

Last edited by Scott; 11-11-2013 at 08:21 PM.. Reason: Code tags
# 2  
Old 11-11-2013
You could use a perl script:

Code:
#!/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:

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


Last edited by Chubler_XL; 11-11-2013 at 10:08 PM.. Reason: Update to fetch field #2 and append result to #3
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. UNIX for Beginners Questions & Answers

Sha256 , copy file to new filename

Hello, i want to create a sha256 hash for a file and copy the source file under new filename as : sha256hash_sourcefilename Input : sha256sum FILE Example : sha156sum mounttest.123 Output HASH_FILE How to do this ? e.g.: ... (1 Reply)
Discussion started by: bdittmar
1 Replies

3. Shell Programming and Scripting

Matching column value from 2 different file using awk and append value from different column

Hi, I have 2 csv files. a.csv HUAWEI,20LMG011_DEKET_1296_RTN-980_IDU-1-11-ISV3-1(to LAMONGAN_M),East_Java,20LMG011_DEKET_1296_RTN-980_IDU-1,20LMG011,20LMG 027_1287_LAMONGAN_RTN980_IDU1,20LMG027,1+1(HSB),195.675,20LMG011-20LMG027,99.9995,202.6952012... (7 Replies)
Discussion started by: tententen
7 Replies

4. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

5. Shell Programming and Scripting

Append a specific keyword in a text file into a new column

All, I have some sample text file(.csv) in the below format. In my actual file there are at least 100K rows. date 03/25/2016 A,B,C D,E,F date 03/26/2016 1,2,3 4,5,6 date 03/27/2016 6,4,3 4,5,6 I require the following output where in the date appeared at different locations need to... (3 Replies)
Discussion started by: ks_reddy
3 Replies

6. Shell Programming and Scripting

Match value in column and append file with new values

Hi, I need help to match two files based on two columns. file_1 ID AA An Ca Ele Pro Su Ot Tra g13950 No No Yes No Yes Yes Yes Yes g05760 Yes No No No No Yes Yes Yes g12640 No No No No No No No No k17720 No Yes No No No No No Yes g05640 Yes Yes Yes No No Yes Yes Yes file_2 ... (8 Replies)
Discussion started by: redse171
8 Replies

7. Shell Programming and Scripting

Append data to first column delimited file

Hi, I have a data like Input: 12||34|56|78 Output: XYZ|12||34|56|78 I tried like this , but it puts it on another line awk -F "|" ' BEGIN {"XYZ"} {print $0} 'file Any quick suggessitons in sed/awk ? am using HP-UX (3 Replies)
Discussion started by: selvankj
3 Replies

8. UNIX for Dummies Questions & Answers

add (append) a column in a tab delimited file

I have a file having the following entries: test1 test2 test3 11 22 33 22 44 66 99 99 44 --- I want to add a column so that the above file becomes: test1 test2 test3 notest 11 22 33 * 22 44 66 * 99 99 44 * --- Thanks (6 Replies)
Discussion started by: mary271
6 Replies

9. Shell Programming and Scripting

Append a new column in a file

Hi all, I need to append 'ls --' command output as a new column in a existing file. for example, when i do ls -- i will get the below, aaa_import.csv bbb_import.csv ccc_import.csv ddd_import.csv ffff_import.csv i need to cut the aaa, bbb, ccc, ddd and append this a new column... (5 Replies)
Discussion started by: baskivs
5 Replies

10. Shell Programming and Scripting

How to append database column to a delimited file

Hi, I have the below flat filewith ~ as delimiter emp.no~dept.name I need to append corresponding emp.name column which will come from database based on emp.no in the flat file. I need the output as dept.name~emp.name Can anyone please help me in resolving this issue.. I tried the... (2 Replies)
Discussion started by: siri_886
2 Replies
Login or Register to Ask a Question