文件1:
chr1 11868 14409 ENST00000456328.2 0 + 11868 11868 0 3 359,109,1189, 0,744,1352,
chr1 12009 13670 ENST00000450305.2 0 + 12009 12009 0 6 48,49,85,78,154,218, 0,169,603,965,1211,1443,
chr1 14403 29570 ENST00000488147.1 0 - 14403 14403 0 11 98,34,152,159,198,136,137,147,99,154,37, 0,601,1392,2203,2454,2829,3202,3511,3864,10334,15130,
chr1 17368 17436 ENST00000619216.1 0 - 17368 17368 0 1 68, 0,
chr1 29553 31097 ENST00000473358.1 0 + 29553 29553 0 3 486,104,122, 0,1010,1422,
chr1 30266 31109 ENST00000469289.1 0 + 30266 30266 0 2 401,134, 0,709,
chr1 30365 30503 ENST00000607096.1 0 + 30365 30365 0 1 138, 0,
chr1 34553 36081 ENST00000417324.1 0 - 34553 34553 0 3 621,205,361, 0,723,1167,
chr1 35244 36073 ENST00000461467.1 0 - 35244 35244 0 2 237,353, 0,476,
chr1 52472 53312 ENST00000606857.1 0 + 52472 52472 0 1 840, 0,
文件2:
ENST00000456328
ENST00000450305
预期输出:
chr1 11868 14409 ENST00000456328.2 0 + 11868 11868 0 3 359,109,1189, 0,744,1352,
chr1 12009 13670 ENST00000450305.2 0 + 12009 12009 0 6 48,49,85,78,154,218, 0,169,603,965,1211,1443,
我更喜欢使用 awk 或其他一些 bash 程序。
答案1
正如评论中提到的,这是完美的:
grep -f file2 file1
如果您仍然喜欢使用awk:
awk 'FNR==NR { a[$1] = $1;next} { split($4,key,"."); if ( a[key[1]]){print}}' file2 file1
使用简单的 for 循环(与第一个 grep 相同):
for match in $(<file2); do grep $match file1; done