匹配特定列的 grep 文件 [英] grep file matching specific column

查看:49
本文介绍了匹配特定列的 grep 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想保留 results.txt 中与 uniq.txt 中的 ID 匹配的行,基于 results.txt<的第 3 列中的匹配/代码>.通常我会使用 grep -f uniq.txt results.txt,但这并没有指定第 3 列.

I want to keep only the lines in results.txt that matched the IDs in uniq.txt based on matches in column 3 of results.txt. Usually I would use grep -f uniq.txt results.txt, but this does not specify column 3.

uniq.txt

9606
234831
131
31313

结果.txt

readID  seqID   taxID   score   2ndBestScore    hitLength       queryLength     numMatches
A00260:70:HJM2YDSXX:4:1111:15519:16720  NC_000011.10    9606    169     0       28      151     1
A00260:70:HJM2YDSXX:3:1536:9805:14841   NW_021160017.1  9606    81      0       24      151     1
A00260:70:HJM2YDSXX:3:1366:27181:24330  NC_014803.1     234831  121     121     26      151     3
A00260:70:HJM2YDSXX:3:1366:27181:24330  NC_014973.1     443143  121     121     26      151     3

推荐答案

您可以将 grepsed 结合使用来操作输入模式并实现您的目标寻找

You can use grep in combination with sed to manipulate the input patterns and achieve what you're looking for

grep -Ef <(sed -e 's/^/^(\S+\s+){2}/;s/$/\s*/' uniq.txt) result.txt

如果你想匹配 nth 列,将上面命令中的 2 替换为 n-1

If you want to match nth column, replace 2 in above command with n-1

输出

A00260:70:HJM2YDSXX:4:1111:15519:16720  NC_000011.10    9606    169     0       28      151     1
A00260:70:HJM2YDSXX:3:1536:9805:14841   NW_021160017.1  9606    81      0       24      151     1
A00260:70:HJM2YDSXX:3:1366:27181:24330  NC_014803.1     234831  121     121     26      151     3

这篇关于匹配特定列的 grep 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆