Awk replace a column with its hash value

前端 未结 5 1732
你的背包
你的背包 2020-12-06 18:10

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.

5条回答
  •  感情败类
    2020-12-06 18:49

    You might have a better time with read than awk, though I haven't done any benchmarking.

    the input (scratch001.txt):

    foo|bar|foobar|baz|bang|bazbang
    baz|bang|bazbang|foo|bar|foobar
    

    transformed using read:

    while IFS="|" read -r one fish twofish red fishy bluefishy; do
      twofish=`echo -n $twofish | md5sum | tr -d "  -"`
      echo "$one|$fish|$twofish|$red|$fishy|$bluefishy"
    done < scratch001.txt
    

    produces the output:

    foo|bar|3858f62230ac3c915f300c664312c63f|baz|bang|bazbang
    baz|bang|19e737ea1f14d36fc0a85fbe0c3e76f9|foo|bar|foobar
    

提交回复
热议问题