0

I have a file (A.txt ; sep="\t") :

blabla  lili
bloblo  lulu

and I want to print in a specific place certain data of A.txt in B.txt in order to generate C.txt.

B.txt (sep=","):

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
,,,,,,,,,,
*reporting.

Example for C.txt (sep=","):

kit
Software Version = lili
Date And Time of Export =
Experiment Name =
Instrument Software Version =
Instrument Type = CFX
Instrument Serial Number =
Run Start Date = lulu
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
,,,,,,,,,,
*reporting.

The trick is to set " = " as separator for B.txt in order to print the data of A.txt in the $2 of B.txt. I've try stuff like:

awk 'BEGIN{OFS=FS=" = "} NR==2{stuff} ; NR==8{stuff} } 1' A.txt B.txt > C.txt

But i didn't figure it out. Any ideas?

Thanks

2
  • I see a problem in the format of our B.txt in that it doesn't have a very consistent structure: The first line only has one field, then there are several lines with =-style assignments, and then (just) one line that is actually CSV ... ? Also (and even more important), how do we determine which entry in A.txt is to be pasted to which line in B.txt - is the blabla and bloblo in A.txt completely irrelevant, or does it actually indicate where in B.txt the following string belongs?
    – AdminBee
    Jul 9, 2020 at 8:33
  • The data that I want to print from A.txt to B.txt will be hardcoded. that's why it's not about key/value. all the file B.txt is in csv, just the first 12 lines have only one column
    – nstatam
    Jul 9, 2020 at 8:44

1 Answer 1

1
awk -F'\t' '
  FNR==NR{ a[NR]=$2; next }
  FNR==2{ print $0, a[1]; next }
  FNR==8{ print $0, a[2]; next }
  1
' A.txt B.txt > C.txt

Or with more meaningful descriptions:

awk -F'\t' '
  FNR==NR{ a[NR]=$2; next }
  $1=="Software Version"{ print $0, a[1]; next }
  $1=="Run Start Date"{ print $0, a[2]; next }
  1
' A.txt FS=" =" B.txt > C.txt
4
  • Thanks for the response. But it doesn't works. Nothing more than B.txt is print in C.txt
    – nstatam
    Jul 9, 2020 at 9:13
  • Actually nothing print at all
    – nstatam
    Jul 9, 2020 at 9:19
  • It should print nothing if A.txt is an empty file. But otherwise it should print at least B.txt.
    – Freddy
    Jul 9, 2020 at 9:38
  • sorry it's my fault I had a problem with one file. Thanks it seems to works well !
    – nstatam
    Jul 9, 2020 at 9:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .