Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hashing a list of emails containing multiple columns

I have a text file that 2 columns: ID and Email Address. I want to output a file that reads each line and outputs the ID along with the sha256 hashed version of the email.

Input example:

200015 jhon.smith@gmail.com
200016 larry.power@gmail.com

Output file:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

200015  ae40fc9f2cf25b2b9f3cc89020ece6dd01015631d5c87483dcd3cd0c296b5eeb
200016  e420b22e7b6601ce3f416f059626688b5bc01f2c108e05798b9df4f83da3f991

I am using the following code:

while read line; do
    echo $line | cut -d' ' -f2 | tr -d " \t\n\r" | sha256sum | cut -f1 -d' '
done < file_name

This only outputs the hashed emails. How can I adapt the code to include the IDs?

>Solution :

Try this:

while read -r ID EMAIL
do
  echo "$ID $( echo "$EMAIL" | sha256sum | cut -f1 -d' ')"
done < file_name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading