Find a blank field and replace values to NA

Hi All,

i have a file like

col1	col2	col3
13	24	NA
12	13	14
11	12	13
14	22	NA
18	26	NA

in this file if i found "NA" other values in the line are also replace by NA

Could you help me!

it should be straight forward, What have you tried?

HI,

i tried to fild the NA values and still finding to replace the fist col1 values to NA

awk -F\\t '{ if (NR == 1) { for (i=1;i<=NF;i++){if ($i=="col3") { c=i } } };if (NR != 1) {if ($c ~ /NA/ )' filename.tsv

The 'NA' can appear ONLY in the last/third field/column or anywhere in the record/line?

yes it present in 3d col only

If it's really just in Col 3:

awk '$3=="NA" {$1=$2=$3} 1' OFS="\t" file
col1    col2    col3
NA    NA    NA
12    13    14
11    12    13
NA    NA    NA
NA    NA    NA
awk 'FNR==1 {print;next} {($3=="NA") && $1="NA"}1' OFS='\t' myFile

Hi vgresh, ur code is working for on column if i add ine more then its replace "1" in that column,

Hi Rudic ur code is working fine ,

Both guys Thank you for helping me