SED - how do I convert a decimal number to asterisk

Hi, My animal ID's have two zeros in them and are also converting to asterisk. I only need to change the zero values in columns two and three. I would appreciate any help.

This is my data structure:

 head phendata.txt
201008809 0.0 0.0
201008810 0.0 0.0
201008813 0.0 0.0
201014103 0.703125 -0.262959
201014118 0.703125 -1.26296
201014136 0.0 0.0
201017233 0.0 0.0
201017322 0.703125 0.669447
201017640 0.703125 -0.330553
201024891 0.703125 2.16991

This is my command so far:

head phendata.txt | sed 's/\0.0/*/g'
2*08809 * *
2*0881*.*.0
2*08813 * *
2*14103 0.703125 -0.262959
2*14118 0.703125 -1.26296
2*14136 * *
2*17233 * *
2*17322 0.703125 0.669447
2*1764*.703125 -0.330553
2*24891 0.703125 2.16991

I don't want to take the long way and use awk - i would like to learn how sed specifically recognises 0.0 and not 00. Thanks in advance :wink:

How about?

sed 's/ 0\.0/*/g'

So what is the output you are expecting...

Hmm i think this ( sed 's/ 0\.0/ */g') will work with a space added... Thanks!

The output should look like this (Column 2 and 3 0.0 values converted to asterisks)

201008809 * *
201008810 * *
201008813 * *
201014103 0.703125 -0.262959
201014118 0.703125 -1.26296
201014136 * *
201017233 * *
201017322 0.703125 0.669447
201017640 0.703125 -0.330553
201024891 0.703125 2.16991

---------- Post updated at 06:32 PM ---------- Previous update was at 05:06 PM ----------

Hmm yeah that hasnt worked. For values of 0.0811563 it is replacing the 0.0...

Y05DL0108 0.703125 1.08116
Y05DL0110 0.703125 *811563
Y05DL0115 0.703125 *811563

Try this one then...

sed 's/0\.0 /*/g;s/0\.0$/ */g' file
1 Like

For dealing with columns, use a tool that understands columns, like awk, so you can do a straightforward 'check if this exact column matches this exact string' comparison, instead of weird convolutions with sed to try and force a stream tool to do operations on columns.

awk '{ for (N=1; N<=NF; N++) if($N  == "0.0" ) $N="*" } 1' filename
1 Like

This is great, both of these are working for me. I appreciate the help!
Cheers.