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:
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