Operating System - HP-UX
1834020 Members
3095 Online
110063 Solutions
New Discussion

grep -w "string" equivalent

 
Sup
Advisor

grep -w "string" equivalent

Hello,

I am using grep to search for a string. I want only rows with exact match, Is there a
"grep -w string" equivalent on HP?
5 REPLIES 5
Marco Santerre
Honored Contributor

Re: grep -w "string" equivalent

gerp -w string should work fine on HP as well
Cooperation is doing with a smile what you have to do anyhow.
John Poff
Honored Contributor

Re: grep -w "string" equivalent

Hi,

The '-w' switch only works with grep in HP-UX 11i. Here is a recent post asking a similar question:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xef3f28c64656d71190080090279cd0f9,00.html

JP
Yogeeraj_1
Honored Contributor

Re: grep -w "string" equivalent

hi,

If you want to grep for a string regardless of case: grep -i " some string "

Note the spaces before and after.

According to the man pages, there is no -w for 10.20 or 11.0 (and very little likelihood that the 11i version will be backported to 11.0, no possibility for the almost obsolete 10.20 systems).

hth
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Tom Danzig
Honored Contributor

Re: grep -w "string" equivalent

# cat testfile
some text and search string
search string
search string and some text

Standard grep:
# grep "search string" testfile
some text and search string
search string
search string and some text

Syntax to get only exact line match
# grep "^search string$" testfile
search string

The "^" signifies the begining of the line and the "$" signifies the end and, therefore, only an exact match of "search string" (with no other text in the line) will be printed.

Martin Johnson
Honored Contributor

Re: grep -w "string" equivalent

Tom,

"grep -w" allows you to search for a word. In other words, "string" preceded/superceded by white space and/or begin/end line.

The use of " string " will only match if the white space is a space, not if it is a .

HTH
Marty