0

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
Avihoo Mamka
  • 4,656
  • 3
  • 31
  • 44
ramesh
  • 21
  • 1
  • 6
  • RAMESH|~|12345|~|ABCD RAMESH|~|12345|~| – ramesh Jan 07 '16 at 07:43
  • If this the delimted file i need to replace 2nd column with its corresponding hash value , how can i modify the above script , please advice. – ramesh Jan 07 '16 at 07:44
  • You can use another delimiter for your `awk` script. Use `-F "|" as your delimiter. – Avihoo Mamka Jan 07 '16 at 07:53
  • RAMESH|12345|TEST|HI U| PRAVAS|67676|TEST|HI U| PRAVAS|676766|SETT|HI U| – ramesh Jan 07 '16 at 09:04
  • Im getting out replacing all my delimiter with space .. No idea whats wrong – ramesh Jan 07 '16 at 09:05
  • RAMESH d577273ff885c3f84dadb8578bb41399 TEST HI U PRAVAS 3a408343450221a54e66489c8bfc4cfd TEST HI U PRAVAS cb966e594d6880db177d7bf0abf35b62 SETT – ramesh Jan 07 '16 at 09:07
  • please suggest whats going on with this – ramesh Jan 07 '16 at 09:07
  • I don't understand your problem.. You can change the delimiter to space as well.. – Avihoo Mamka Jan 07 '16 at 09:14
  • the problem is my input file is having pipe (|) delimiter file , when im using the above script its throwing correct output but all the (|) pipe delimiter are getting replaced with space in the out put file. Ex:: RAM|TEST o/p RAM d577273ff885 , i need it as RAM|d577273ff885 – ramesh Jan 07 '16 at 09:25
  • please let me know if it is still now clear – ramesh Jan 07 '16 at 09:25

1 Answers1

1

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
Avihoo Mamka
  • 4,656
  • 3
  • 31
  • 44