ramesh
ramesh

Reputation: 21

I need to repalce a column with its correspoding MD5 value using unix shell scripting

This is my code from previous posts, but it's not working with other delimited files.

Can you please help me in modifying this below script for any other delimited files?

 awk '{
  tmp="echo " $2 " | openssl md5 | cut -f2 -d\" \""
  tmp | getline cksum
   $2=cksum
  print
  }' < sample

Upvotes: 0

Views: 102

Answers (1)

Avihoo Mamka
Avihoo Mamka

Reputation: 4786

You need to add 2 things to your awk script:

  1. The -F parameter which you can set your input delimiter by, and set it to pipe (|)

  2. the -v OPS parameter which set the output delimiter from the default space to your desired one (e.g pipe)

Try this code:

awk -F '|' -v OFS='|' '{
  tmp="echo " $2 " | openssl md5 | cut -f2 -d\" \""
  tmp | getline cksum
   $2=cksum
  print
  }' < sample

Upvotes: 1

Related Questions