我有一个很大的txt文件,我正在寻找以物种名称" ABS"开头的seq id。当我做grep" ABS"时,我只得到ABS的列表,但不是seq id后面跟着那个词。例如,我正在寻找的列表是这样的:
ABS|contig05671,
ABS|contig04453,
ABS|CL5170Contig1,
ABS|contig02526,
但是,当我这样做时,grep" ABS" filename.txt,我得到的结果如下:
ABS,
ABS,
ABS,
ABS,
非常感谢任何帮助。提前谢谢。
答案 0 :(得分:1)
来自man grep
:
Context Line Control
-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines.
Places a line containing a group separator (--) between
contiguous groups of matches. With the -o or --only-matching
option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines.
Places a line containing a group separator (--) between
contiguous groups of matches. With the -o or --only-matching
option, this has no effect and a warning is given.
-C NUM, -NUM, --context=NUM
Print NUM lines of output context. Places a line containing a
group separator (--) between contiguous groups of matches. With
the -o or --only-matching option, this has no effect and a
warning is given.
因此,如果您需要匹配的行和下一行,则执行grep -A1 ABS file.txt
,对于前一行-B1
也类似。
但是,如果要以另一种方式格式化结果(例如,将两行放在一个上并用管道符分隔),则需要使用与grep
不同的工具。 grep
会进行搜索,而您也需要进行编辑。