Help with replace column data with specific word

Input file:

Populus_trichocarpa	30	0	50	0	0 US
Vitis_vinifera	1	18	2	8	6 US
Populus_trichocarpa	1	5	100	0	0 US
Arabidopsis_lyrata_subsp._lyrata	0	90	0	0	0 US
Glycine_max	0	2	3	0	70 UK

Desired output file:

Populus_trichocarpa	YES	NO	YES	NO	NO US
Vitis_vinifera	YES	YES	YES	YES	YES US
Populus_trichocarpa	YES	YES	YES	NO	NO US
Arabidopsis_lyrata_subsp._lyrata	NO	YES	NO	NO	NO US
Glycine_max	NO	YES	YES	NO	YES UK

If the column 2-6, any column shown equal to 0, replace it with "NO"
If the column 2-6, any column shown except 0, replace it with "YES"

Thanks for any advice.

Hi

awk '{for(i=2;i<=NF;i++)$i=$i==0?"NO":"Yes";}1' file

Guru.

1 Like

Hi Guru,

I just edited my question.
Do you have any idea if just focus on the data that in column 2-6?
Because some of my input file, column 7 also got some data which I just need to print out them.
I only interested to replace the data in column 2-6 into "YES" or "NO" if fully requirement.
Many thanks.

Hi, have a look at the for statement. On every line it is being executed so that every field starting from field 2 ( i=2 ) is processed. In the suggestion provided by guruprasadr it currently stops at the last field ( i<=NF ) . What do you think would make it stop processing at the field before the last field?

1 Like

Thanks for reminding :slight_smile:
The below command worked fine:

awk '{for(i=2;i<=NF;i++)$i=$i==0?"NO":"Yes";}1'