ファイル (A.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
,,205920777.1,A01,Unkn-01,,,
,,neg5,A02,Neg Ctrl-01,,,
,,pos6,A03,Pos Ctrl-01,,,
,,,,,,,,,,
*reporting.
「Sample Type」列に「Unkn」の場合「Patient」というパターンが含まれている場合「Explained Results」列に「Negative」の場合「NC」、「Pos」の場合「PC」を印刷したいと思います。次の出力を取得するには(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
,,205920777.1,A01,Unkn-01,,Patient,,
,,neg5,A02,Neg Ctrl-01,,NC,,
,,pos6,A03,Pos Ctrl-01,,PC,,
,,,,,,,,,,
*reporting.
私は同様のことを試しました:
awk -F',' -v OFS="," '(NR>1 && $5="Unkn"*){print ...}' A.txt > B.txt
しかし、私はこの問題を解決できませんでした。誰かがアイデアを持つことができますか?
ありがとう
答え1
上の方のように比較が必要です==
。しかし、~
演算子を使用してフィールドを正規表現と比較することはまさにその目的です。
pat.awk
:
BEGIN{FS=OFS=","}
$5 ~ /Unkn/{$7="Patient,"}
$5 ~ /Neg/{$7="NC,"}
$5 ~ /Pos/{$7="PC,"}
{print}
$ awk -f pat.awk A.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,,Patient,,
,,neg5,A02,Neg Ctrl-01,,NC,,
,,pos6,A03,Pos Ctrl-01,,PC,,
,,,,,,,,,,
*reporting.
1行を好む場合:
awk -F ',' -v OFS=',' '$5~/Unkn/{$7="Patient,"}$5~/Neg/{$7="NC,"}$5~/Pos/{$7="PC,"}1' A.txt