grep
1つのファイルのパターンを2番目のファイルから検索するために使用したいと思います。私のスキーマファイルは次のとおりです。
K02217
K07448
KO8980
検索するファイルは次のとおりです。
>aai:AARI_24510 proP; proline/betaine transporter; K03762 MFS transporter, MHS family, proline/betaine transporter
>aai:AARI_26600 ferritin-like protein; K02217 ferritin [EC:1.16.3.1]
>aai:AARI_28260 hypothetical protein
>aai:AARI_29060 ABC drug resistance transporter, inner membrane subunit; K09686 antibiotic transport system permease protein
>aai:AARI_29070 ABC drug resistance transporter, ATP-binding subunit (EC:3.6.3.-); K09687 antibiotic transport system ATP-binding protein
>aai:AARI_29650 hypothetical protein
>aai:AARI_32480 iron-siderophore ABC transporter ATP-binding subunit (EC:3.6.3.-); K02013 iron complex transport system ATP-binding protein [EC:3.6.3.34]
>aai:AARI_33320 mrr; restriction system protein Mrr; K07448 restriction system protein
私が試したコマンドは次のとおりです。
fgrep --file=pattern.txt file.txt >> output.txt
これにより、パターンが見つかったfile.txtの行が印刷されます。見つかったパターンを含む列を印刷するには、この情報が必要です。だからこんな感じ:
K07448 mrr; restriction system protein Mrr; K07448 restriction system
K02217 ferritin-like protein; K02217 ferritin [EC:1.16.3.1]
誰でも私に何をすべきかを提案できますか?
ベストアンサー1
追加の列があっても問題ない場合は、およびをjoin
使用してgrep
これを実行できます。
$ join <(grep -of patterns.txt file.txt | nl) \
<(grep -f patterns.txt file.txt | nl)
1 KO3322 proteinaseK (KO3322)
2 KO3435 Xxxxx KO3435;folding factor
3 KO3435 Yyyyy KO3435,xxxx