This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to replace column values if equal specific value to specific character and if not equal these value replace it by another character in Linux ?

Hi everyone

I have file with 3 column, I need check if the 3rd column < 10 replace value by character T but if not < 10 replace value by character S

The file like

T227 1   10.736439
T228 1    5.690412
T229 1    8.534977
T230 1   10.711639
T231 1    6.298395

Thank you for your help me

linux awk

What was your approach to solving this? Where did you have a problem?

I need replace 3rd column values with specific character if it <10 but if it not replace it with another character in huge file

I got that. What did you do to try to solve it?

I used awk

awk '{if($3 <8) print $1,$2,$3 = "c"}' file_name

but I can't refer to another values

Thank you barslmn

I used this command

awk '{if ($3 <10)print $1,$2,$3="c"; else print $1,$2,$3="s"}' file_name

You can do what you've said twice, using an intermediate file to save the results. Code not checked, just adapted your example:

awk '{if($3 <10) print $1,$2,$3 = "c"}' input.tsv > output1.tsv
awk '{if($3 >=10) print $1,$2,$3 = "s"}' output1.tsv > output2.tsv

0 answers

No answers yet.

Log in to answer this question.