1

I have a tab-delimited file as below:

1 f1 0 10
1 f2 0 20
1 f3 0 30

I want to replace the third column with a column that starts with 0.01, and in each row, it is going to be added 0.01. Something like this one:

1 f1 0.01 10
1 f2 0.02 20
1 f3 0.03 30

I am very new to Linux; and I don't know how to solve this problem. I wrote this code, but it doesn't work.

j=1/100
arr[$j]="$c3"
j=$((j+(1/100)))
awk '{print $1,$2,$3="$c3",$4}' x.txt> y.txt

The result is:

1 f1 $c3 10
1 f2 $c3 20
1 f3 $c3 30

Would you please help me to solve this problem? Thanks

Smiled
  • 35
  • 4

1 Answers1

2

Simple in just awk:

$ awk 'BEGIN { FS=OFS="\t"; a=0.01 } { $3 = sprintf("%.02f", a); a+=0.01 } 1' input.tsv
1   f1  0.01    10
1   f2  0.02    20
1   f3  0.03    30
Shawn
  • 47,241
  • 3
  • 26
  • 60