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

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

问题描述

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

  9606 ENSP00000239223 DUSP1 BLAST 
9606 ENSP00000239223 DUSP1-001 Ensembl

我想检索第一行,但不是第二行。

我尝试了几个命令:

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

但是他们似乎都没有工作。我应该使用哪个选项?

解决方案

您遇到的问题是 dash 被认为是由 grep 作为单词分隔符。



你应该试试这个命令:

  grep'\sDUSP1 \''文件

以确保您的单词有空格。


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.

I tried several commands as:

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

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

解决方案

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

You should try this command :

grep '\sDUSP1\s' file

to ensure that there's spaces around your word.

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

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