LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   command for grep the exact word (https://www.linuxquestions.org/questions/linux-newbie-8/command-for-grep-the-exact-word-722394/)

nagendrar 04-28-2009 11:33 PM

command for grep the exact word
 
I have two lines in a file like below

Host *
Host-specific *

Here I want to grep the "Host *" line only.

I had tried following way but I did not get exact line

grep -w Host filename


Please give the suggestions for grep exact line using specific word.


Thanks,
Nagendra.

syg00 04-29-2009 12:01 AM

You already have it - it is simply that you have the wrong understanding of what a "word" is.
Have a look at the manpage again.

Simplest for what you want might be to use character classes - [[:space:]] say - before and after the "word" you want. May lead to other surprises of course ...

chrism01 04-29-2009 01:38 AM

a simple soln:
Code:

grep 'Host ' filename

nagendrar 04-29-2009 02:06 AM

If there is tab space between Host and * then we did not get output using

grep 'Host ' filename.



Thanks,
Nagendra

flopypl 04-29-2009 02:10 AM

yesterday's thread: http://www.linuxquestions.org/questi...-linux-721931/

mayby that will help you something.

colucix 04-29-2009 03:12 AM

Quote:

Originally Posted by nagendrar (Post 3524373)
If there is tab space between Host and * then we did not get output using

grep 'Host ' filename.

Code:

grep Host[[:space:]] filename
the [:space:] class includes space, TAB, formfeed and so on.

knudfl 04-29-2009 02:16 PM

How about

cat <file> | grep "\Host\ "

H_TeXMeX_H 04-29-2009 02:33 PM

You may also want to try 'grep -x'

Code:

      -x, --line-regexp
              Select only those matches that exactly match the whole line.

Not sure if that's what you want to do tho.


All times are GMT -5. The time now is 12:04 AM.