使用 grep 仅提取整个单词 [英] Extract only whole word using grep

查看:37
本文介绍了使用 grep 仅提取整个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的文本文件.我需要提取包含确切单词DUSP1"的所有行.这是行的示例:

I've got a big text file. I need to extract all the lines which contains the exact word "DUSP1". Here an example of the lines:

9606    ENSP00000239223 DUSP1   BLAST
9606    ENSP00000239223 DUSP1-001 Ensembl

我想检索第一行而不是第二行.

I want to retrieve the first line but not the second one.

我尝试了几个命令:

grep -E "^DUSP1"
grep '<DUSP1>'
grep '^DUSP1$'
grep -w DUSP1

但它们似乎都不起作用.我应该使用哪个选项?

But none of them seem to work. Which option should I use?

推荐答案

您面临的问题是破折号 (-) 被 grep 视为一个词分隔符.

The problem you are facing is that a dash (-) is considered by grep as a word delimiter.

你应该试试这个命令:

grep 'sDUSP1s' file

以确保您的单词周围有空格.
或者使用词边界:

to ensure that there's spaces around your word.
Or use words boundaries :

grep 'DUSP1' file

这篇关于使用 grep 仅提取整个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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