リスト.txt
GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
GETID_9248_knownids_6/10_Confidence_0.439_Length_2474
GETID_11084_knownids_3/3_Confidence_0.600_Length_1451
GETID_15916_knownids_10/11_Confidence_0.324_Length_1825
サンプル1.txt
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample1
sampletextforsample1
sampletextforsample1
>GETID_18457_knownids_1/2_Confidence_0.625_Length_2532
sample2textforsample1
sample2textforsample1
sample2textforsample1
sample2textforsample1
サンプル2.txt
>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451
sampletextforsample2
sampletextforsample2
>GETID_67838_knownids_3/3_Confidence_0.600_Length_1451
sample2textforsample2
sample2textforsample2
サンプル3.txt
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample3
sampletextforsample3
sampletextforsample3
>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825
sample2textforsample3
sample2textforsample3
出力.txt
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample1
sampletextforsample1
sampletextforsample1
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample3
sampletextforsample3
sampletextforsample3
>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451
sampletextforsample2
sampletextforsample2
>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825
sample2textforsample3
sample2textforsample3
list.txtの各行を読みたい(大括弧内の値をキャプチャして(GETID_ {17049})みんな知ってる{1/2}_Confidence_1.0_Length_{2532}) 複数行の example1.txt、Sample2.txt、Sample3.txt と比較して list.txt(output.txt) と一致する場合、このファイルの内容を印刷します。出力にはlist.txtと正確に一致するものを含める必要があります。 awk/sed/perl のお手伝いをいただきありがとうございます。
ベストアンサー1
提供されたソリューションを少し変更するとザイルズ存在するこれ質問(とも呼ばれる)jw013output.txt
)、順序が入力シーケンスに基づいており、質問に記載されている順序とは異なることを除いて、要求された効果を得ることができます。
awk -v patterns_file=list.txt '
BEGIN {
while (getline < patterns_file)
patterns_array[">" $0] = 1
close(patterns_file)
}
$0 in patterns_array { print; getline; print }
' sample[1-3].txt
出力:
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample1
>GETID_11084_knownids_3/3_Confidence_0.600_Length_1451
sampletextforsample2
>GETID_17049_knownids_1/2_Confidence_0.625_Length_2532
sampletextforsample3
>GETID_15916_knownids_10/11_Confidence_0.324_Length_1825
sample2textforsample3
編集する
複数行のレコードが機能するようにするには、適切なレコード区切り文字(RS
)を使用します。あなたの場合は、greater-than
ファイルの先頭(^>
)またはnew-line
後ろgreater-than
(\n>
)またはnew-line
ファイルの終わり(\n$
)に設定するのが良いオプションです。提供された入力について。
次のように動作する必要があります。
awk -v patterns_file=patterns.txt '
BEGIN {
while (getline < patterns_file)
patterns_array[$0] = 1
close(patterns_file)
RS="^>|\n>|\n$"
}
$1 in patterns_array { print ">" $0 }
' sample[1-3].txt
編集2
各レコードを一度だけ出力するには、patterns_array
後の出力からそのレコードを削除します。
awk -v patterns_file=patterns.txt '
BEGIN {
while (getline < patterns_file)
patterns_array[$0] = 1
close(patterns_file)
RS="^>|\n>|\n$"
}
$1 in patterns_array { print ">" $0; delete patterns_array[$1] }
' sample[1-3].txt