Operating System - HP-UX
1753316 Members
5053 Online
108792 Solutions
New Discussion юеВ

how to search the exact word using grep in hpux

 
SOLVED
Go to solution
senthil_kumar_1
Super Advisor

how to search the exact word using grep in hpux

Hi

Normally we use below command to find the line containing exact word in linux.

Ex: #grep -w ze4egi /etc/passwd.

But it is not working in hp-ux.

how to solve this?
18 REPLIES 18
Kenan Erdey
Honored Contributor

Re: how to search the exact word using grep in hpux

hi,

grep -w also works in hp-ux. what's the problem ?
Computers have lots of memory but no imagination
James R. Ferguson
Acclaimed Contributor

Re: how to search the exact word using grep in hpux

Hi:

What version of HP-UX? The '-w' switch to 'grep' works as "...the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore."

You can roll-your-own matches with 'grep' with your own regular expresssions and/or extended ones.

Regards!

...JRF...
senthil_kumar_1
Super Advisor

Re: how to search the exact word using grep in hpux

My HP unix version is 10.20, 11.00 and 11.11.


I am getting following error when running this command.


root@lgapps:/root > grep -w ze4egi /etc/passwd
grep: illegal option -- w
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]


Ganesan R
Honored Contributor

Re: how to search the exact word using grep in hpux

Hi,

What is the output you are getting?

Above command syntax suppose to work.

try this if that doesn't work.

#grep -i /etc/passwd
Best wishes,

Ganesh.
Sunny123_1
Esteemed Contributor

Re: how to search the exact word using grep in hpux

Hello

Try this


grep -i ze4egi /etc/passwd.

Regards
Sunny
Ganesan R
Honored Contributor

Re: how to search the exact word using grep in hpux

Hi,

-w switch is available with grep in 11.X. Not sure why you are getting illegal option message.

Can you check man grep to find if you have that option or not?
Best wishes,

Ganesh.
senthil_kumar_1
Super Advisor

Re: how to search the exact word using grep in hpux

Hi

If use the command

"grep -i ze4egi /etc/passwd"

If getting all the words in output like

wze4egi, ze4egiqwe,

But here i want to search exact word only.

Sunny123_1
Esteemed Contributor

Re: how to search the exact word using grep in hpux

Hi

Can you try this???

more /etc/passwd |grep "ze4egi"

Regards
Sunny
johnsonpk
Honored Contributor
Solution

Re: how to search the exact word using grep in hpux

Hi Senthil ,

This wont be the answer you asked for ,but if you are dealing with the /etc/password it may help u

if you want to extract by username
grep ^"usename:" /etc/passwd

if you are grepping any other field other than the login shell then

grep ":password:" /etc/passwd

grep ":1021:" /etc/passwd


thanks!!
Johnson