Skip to main content
1 of 2
terdon
  • 252.4k
  • 69
  • 480
  • 718

Assuming the first column of your file is empty as you say, you need to shift everything one to the left. When you talk about the 5th field, that's actually the 6th. In any case, the simplest approach I can think of is to first modify your A.txt file so it has a format you can use:

$ awk -F'\t' -v OFS="," '(NR>1 && $6!="NaN"){print ",",$6,$2,$5}' A.txt 
,,205920777.1,A01,Unkn-01
,,205920777.1,A01,Unkn-01
,,neg5,A02,Unkn-09
,,neg5,A02,Unkn-09

That should give you the strings you want to insert into your C.txt. So, to add them, you can do something inelegant like this:

( head -n 13 B.txt 
  awk -F'\t' -v OFS="," '(NR>1 && $6!="NaN"){print ",",$6,$2,$5}' A.txt
  tail -n+14 B.txt ) > C.txt

Which produces:

$ cat C.txt 
kit
Software Version =
Date And Time of Export =
Experiment Name =
Instrument Software Version =
Instrument Type = CFX
Instrument Serial Number =
Run Start Date =
Run End Date =
Run Operator =
Batch Status = VALID
Method = Novaprime
Date And Time of Export,Batch ID,Sample Name,Well,Sample Type,Status,Interpretive Result,Action*,Curve analysis
,,205920777.1,A01,Unkn-01
,,205920777.1,A01,Unkn-01
,,neg5,A02,Unkn-09
,,neg5,A02,Unkn-09
,,,,,,,,,,
*reporting.
terdon
  • 252.4k
  • 69
  • 480
  • 718