I have a csv file as given below,
org1 org2 org3 org4 org5
gene1 100 80 90 80 150
gene2 30 70 50 50 115
gene3 40 120 60 40 105
gene4 20 72 40 60 20
I need to replace the fields are having values greater than 100 with "TRUE". I used the following commands to replace specific values. But I do not know how to replace all the fields which has value greater than 100 with "TRUE".
sed -e 's/100/TRUE/g' org1.xls
Thanks in advance.
RudiC
April 30, 2019, 6:49am
2
Well, greater than (or equal) 100 means three digits and more, right? Try
sed -e 's/[0-9]\{3,\}/TRUE/g' file
org1 org2 org3 org4 org5
gene1 TRUE 80 90 80 TRUE
gene2 30 70 50 50 TRUE
gene3 40 TRUE 60 40 TRUE
gene4 20 72 40 60 20
1 Like
Hello dineshkumarsrk,
Could you please try following.
awk 'FNR==1{print;next} {for(i=1;i<=NF;i++){if($i+0>100){$i="True"}}} 1' Input_file | column -t
Thanks,
R. Singh
1 Like
anbu23
April 30, 2019, 6:59am
5
sed "s/[1-9][0-9]\{2,\}/TRUE/g" file
1 Like
This code also works perfectly with the addition of
>=100
.
Sorry Singh, I forgot to mention in my question that greater than or equal to 100 to be replace with TRUE.
Hello dineshkumarsrk,
Ok sure try following.
awk 'FNR==1{print;next} {for(i=1;i<=NF;i++){if($i+0>=100){$i="True"}}} 1' Input_file | column -t
Thanks,
R. Singh
1 Like