0

I have a tsv file like this:

$ head dd.tsv

rs12184267       1       715265  C       T       0.035954        0.926915        -0.00125872     0.00152815      0.34

rs12184277      1       715367  A       G       0.036063        0.931148        -0.00133899     0.00152247      0.31

rs116801199     1       720381  G       T       0.0362940000000001      0.932145        -0.00120216     0.00151647      0.36

rs12565286      1       721290  G       C       0.036397        0.936321        -0.00126183     0.00151109      0.33

rs116720794     1       729632  C       T       0.036223        0.946579        -0.00107634     0.00150722      0.39

I want to add a new column about Z score, so I used command

awk '{$(++NF)=$8/$9;print}' dd.tsv|head

It returns the following results:

\-0.823689 1 715265 C T 0.035954 0.926915 -0.00125872 0.00152815 0.34

\-0.879485 1 715367 A G 0.036063 0.931148 -0.00133899 0.00152247 0.31

\-0.7927369 1 720381 G T 0.0362940000000001 0.932145 -0.00120216 0.00151647 0.36

\-0.835046 1 721290 G C 0.036397 0.936321 -0.00126183 0.00151109 0.33

\-0.7141234 1 729632 C T 0.036223 0.946579 -0.00107634 0.00150722 0.39

I don't understand why this happends. It seems that the data in the first column is covered by the data that should appear in the ++NF position.

It is worth mentioning that this code performs as expected on awk REPL, but in my machine, it does not work, I've checked version of awk and tried commands like gawk, makw, which have the resluts.

The version I am using is:

$ awk -W version

GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1) Copyright (C) 1989, 1991-2020 Free Software Foundation.

I would appreciate it if you could give me some suggestions.

James Brown
  • 36,089
  • 7
  • 43
  • 59
heiha
  • 1
  • 2
  • 1
    You probably have DOS line endings (\r\n). Since you are using GNU awk, try this: `awk -v RS="\r\n" ... [your code here]` – James Brown Jan 28 '23 at 13:37
  • Unbelievable, this is the answer I want. This problem has been bothering me for almost an afternoon, thank you for your help! – heiha Jan 28 '23 at 13:46

0 Answers0