Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Awk replace a column with its hash value

Tags:

shell

sed

awk

How can I replace a column with its hash value (like MD5) in awk or sed?

The original file is super huge, so I need this to be really efficient.

like image 986
Amir Avatar asked Nov 06 '11 00:11

Amir


1 Answers

I copy pasted larsks's response, but I have added the close line, to avoid the problem indicated in this post: gawk / awk: piping date to getline *sometimes* won't work

awk '{
    tmp="echo " $2 " | openssl md5 | cut -f2 -d\" \""
tmp | getline cksum
close(tmp)
$2=cksum
print
}' < sample 
like image 86
Amir Avatar answered Nov 16 '22 04:11

Amir