我有一个模板文件A.txt
(sep = \t
):
File Name novaprime-ct043904-TB_2140.pcrd
Created By User admin
Notes
ID
Run Started 09/17/2020 01:19:12 UTC
Run Ended 09/17/2020 03:12:22 UTC
Sample Vol 30
Lid Temp 105
Protocol File Name Cll Novaprime.prcl
Plate Setup File Name CFX-TB_2140-20200916.pltd
Base Serial Number CT043904
第二个文件B.txt
(sep = \t
):
Cycle Well Value Target Content
1 A1 5.07368111264623 EC Unkn-01
1 A1 3.06982862746599 FT Unkn-09
1 A1 2.46545646544623 EC Unkn-01
我想将第 10 行A.txt
(粗体部分)中的信息添加到以下新列中B.txt
:Plate Setup File Name CFX-TB_2140-20200916.pltd
为了有C.txt
(sep = \t
):
Cycle Well Value Target Content Plate
1 A1 5.07368111264623 EC Unkn-01 TB_2140
1 A1 3.06982862746599 FT Unkn-09 TB_2140
1 A1 2.46545646544623 EC Unkn-01 TB_2140
为此,我尝试使用“-”作为分隔符的各种 awk 命令,但它不起作用。你知道该怎么做吗?谢谢
答案1
awk 'BEGIN{FS=OFS="\t"}
NR==FNR {if (/^Plate Setup File Name/) {split($2,a,"-");id=a[2]};next}
{if (FNR==1) $6="Plate"; else $6=id} 1' A.txt B.txt > C.txt
这将扫描 中的“印版设置文件名”行A.txt
,将值部分分隔到 上的字段中-
,并存储“印版”部分。处理时B.txt
,它会替换合适的标题条目或板 ID。