nst*_*tam 5 awk text-processing
我有一个数据文件A.txt
(字段分隔符 = \t):
Well Well Type Well Name Dye Target
A1 Unknown HIGH-001 FAM ViroFAM
A1 Unknown HIGH-001 HEX ViroHEX
Run Code Online (Sandbox Code Playgroud)
和一个模板文件B.txt
:
kit
Software Version = NOVA_v1
Date And Time of Export = 07/02/2020 13:44:11 UTC
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
,taq,205920777.1,A01,Unkn-01
,taq,neg5,A02,Unkn-09
,,,,,,,,,,
*reporting.
Run Code Online (Sandbox Code Playgroud)
并且我想打印=
在B.txt
with的第二行之后的替换值VIRO_v1
,但仅当模式ViroHEX
出现在A.txt
.
为了做到这一点,我开始了类似的事情:
awk -F'\t' '
FNR==NR{ a[NR]=$2; next }
$1=="Software Version"{ print $0,"VIRO_v1"; next }
1
' B.txt FS=" =" B.txt > result.txt
Run Code Online (Sandbox Code Playgroud)
但我没有弄清楚带有A.txt
. 你知道怎么做吗?
awk -F'\t' '
NR==FNR{ if ($5=="ViroHEX"){ viro=1 } next }
viro && $1=="Software Version"{ $2="VIRO_v1" }
1
' A.txt FS=" = " OFS=" = " B.txt > result.txt
Run Code Online (Sandbox Code Playgroud)
如果第一个字段等于并出现在第一个文件的第 5 列中的任何位置,则将第二个字段 ( NOVA_v1
)替换为第二VIRO_v1
个文件中的。Software Version
ViroHEX
我假设第二个文件的字段分隔符是<space>=<space>
(不是选项卡)。