-2

I have a CSV file that contain Null value in the 3rd column. I need to update this column with the hash of the second column.

Here a sample code:

#!/bin/bash 
declare key='ABCDEFGHIJKLMNOP123456'
awk -F"," '{$3 = $2"$key";print}' C:/test.csv > C:/output.csv

and here my sample CSV

A,B,?
B,D,?
F,jk,?

the output of my code is not correct and i didn't get Key value but Key variable name

A,B,key
B,D,key
F,jk,key

Can you please help to concat key value with the second column then apply a hash (md5 for example )

Main question is how to apply Hash within AWK.

thanks in advance

Houssem Hariz
  • 55
  • 3
  • 12

1 Answers1

0

I found the solution

awk -F "," -v env_var="$key" '{
        tmp="echo -n "$2env_var" | openssl md5 | cut -f2 -d\" \""
    tmp | getline cksum
    $3=cksum
    print
    }'
Houssem Hariz
  • 55
  • 3
  • 12