【发布时间】:2020-04-27 18:10:59
【问题描述】:
我真的是脚本和堆栈的新手,所以如果我的问题很愚蠢或放错地方,我很抱歉。
我必须在 Bash 中完成一项任务。
我有一个这样的 DATA.anno 文件:
ID POP LOCALITY
1 Apu Italy
2 Apu Italy
3 Tir Albania
4 Tir Albania
5 Ber Germany
6 Ber Germany
我有一个 pop.txt 文件,其中包含前面文件第二列中存在的两个人口名称:
Apu
Ber
现在我想获取另一个文件,该文件仅包含 pop.txt 文件中存在的人口行。在这种情况下,我要获取的输出文件如下:
ID POP LOCALITY
1 Apu Italy
2 Apu Italy
4 Ber Germany
5 Ber Germany
我已尝试使用此脚本,但似乎无法正常工作:
cat pop.txt | while read line; do grep $line DATA.anno | cut -f 2,3 >> outputfile.txt
【问题讨论】:
-
这是一个非常常见的任务:如果它不是标题,你也可以使用 grep 实用程序:
grep -f pop.txt DATA.anno
标签: bash grep bioinformatics cat