Operating System - HP-UX
1760030 Members
2510 Online
108889 Solutions
New Discussion юеВ

Re: grepping for whole words on HP10.20

 
John Connors
Occasional Contributor

grepping for whole words on HP10.20

Is the inclusion of spaces in quotes the only way to grep for a whole word. I understand that the -w flag is not available within 10.20.
I have seen the use of \ in some examples, is this specific to any given platform or should this work in 10.20 and 11.00


TIA
3 REPLIES 3
Mark Greene_1
Honored Contributor

Re: grepping for whole words on HP10.20

you can try the -F option. From the man page:

In the Bourne shell (sh(1)) the following example searches two files,
finding all lines containing occurrences of any of four strings:

grep -F 'if
then
else
fi' file1 file2


mark
the future will be a lot like now, only later
Michael Schulte zur Sur
Honored Contributor

Re: grepping for whole words on HP10.20

Hi John,

there is still the problem, when the string is at the beginning or end of a line. Try the follwing command and see, if it suits you.
grep "search" file | grep -vE "[a-z,A-Z]search[a-z,A-Z]"

greetings,

Michael
Hein van den Heuvel
Honored Contributor

Re: grepping for whole words on HP10.20


How about:

grep -E '(^|[ \t])searchstring([ \t]|$)' file

In English:

Look for a piece of searchstring starting at (the being of a line or with (space or tab)) and ending with ((space or tab) or the end of a line)

fwiw,
Hein.