如何解析然后粘贴到其他文件中

如何解析然后粘贴到其他文件中

我有一个像这样的文件A.txt(字段分隔符= ;):

kit;;;;;;;
Software Version = cti;;;;;;;
Date And Time of Export = 06/02/20  14:14:11;;;;;;;
Experiment Name = taqpath-AB17500-plate7587;;;;;;;
Instrument Software Version = ;;;;;;;
Instrument Type = sds7500fast;;;;;;;
Instrument Serial Number = ;;;;;;;
Run Start Date = Tue Jun 02 12:00:40 CEST 2020;;;;;;;
Run End Date = Tue Jun 02 13:14:42 CEST 2020;;;;;;;
Run Operator = FE;;;;;;;
Batch Status = VALID;;;;;;;
;;;;;;;

并且B.csv(字段分隔符 = \t):

Well    Cycle   Target Name Rn  ΔRn Sample Name 
A1  1   N gene  512629.375  1004.0445   B1000-1 
A1  2   N gene  515089.2188 2157.2146   B1000-1 
A1  3   N gene  514001.7812 -236.8966   B1000-1

我想解析第四行A.txt并将一些信息粘贴到最后一列中,B.csv如下所示:

Well    Cycle   Target Name Rn  ΔRn Sample Name Plate Name
A1  1   N gene  512629.375  1004.0445   B1000-1 plate7587
A1  2   N gene  515089.2188 2157.2146   B1000-1 plate7587
A1  3   N gene  514001.7812 -236.8966   B1000-1 plate7587

我尝试类似的解析部分(并且它有效),但我不知道如何将其粘贴到最后一列B.txt并添加“板名称”作为标题:

awk 'BEGIN{OFS=FS=" = "} NR==4{split($2,a,"-")}

有任何想法吗 ?

谢谢

答案1

如果 A.txt 只有一个实验名称,您可以这样做:

$ awk -F";" '/Experiment Name/{ split($1,a,"-"); } NR>FNR{ if(FNR==1) print $0" Plate name"; else print $0" "a[3] }' A.txt B.csv  > tmp && mv tmp B.csv
Well    Cycle   Target Name Rn  ΔRn Sample Name  Plate name
A1  1   N gene  512629.375  1004.0445   B1000-1  plate7587
A1  2   N gene  515089.2188 2157.2146   B1000-1  plate7587
A1  3   N gene  514001.7812 -236.8966   B1000-1 plate7587

答案2

v1=`awk 'NR==4{print $0}' p3| awk -F "-" '{gsub(";","",$3);print $3}'`

 awk -v v1="$v1" 'BEGIN{print "Well Cycle Target Name Rn ΔRn Sample Plate Name"}NR>1{$NF=v1;print }' p4

输出

Well Cycle Target Name Rn ΔRn Sample Plate Name
A1 1 N gene 512629.375 1004.0445 plate7587
A1 2 N gene 515089.2188 2157.2146 plate7587
A1 3 N gene 514001.7812 -236.8966 plate7587

相关内容