- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to search the exact word using grep in hpu...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:13 AM
тАО05-27-2009 05:13 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:21 AM
тАО05-27-2009 05:21 AM
Re: how to search the exact word using grep in hpux
grep -w also works in hp-ux. what's the problem ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:21 AM
тАО05-27-2009 05:21 AM
Re: how to search the exact word using grep in hpux
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:27 AM
тАО05-27-2009 05:27 AM
Re: how to search the exact word using grep in hpux
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...]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:28 AM
тАО05-27-2009 05:28 AM
Re: how to search the exact word using grep in hpux
What is the output you are getting?
Above command syntax suppose to work.
try this if that doesn't work.
#grep -i
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:30 AM
тАО05-27-2009 05:30 AM
Re: how to search the exact word using grep in hpux
Try this
grep -i ze4egi /etc/passwd.
Regards
Sunny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:31 AM
тАО05-27-2009 05:31 AM
Re: how to search the exact word using grep in hpux
-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?
Ganesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:33 AM
тАО05-27-2009 05:33 AM
Re: how to search the exact word using grep in hpux
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:41 AM
тАО05-27-2009 05:41 AM
Re: how to search the exact word using grep in hpux
Can you try this???
more /etc/passwd |grep "ze4egi"
Regards
Sunny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:44 AM
тАО05-27-2009 05:44 AM
SolutionThis 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:45 AM
тАО05-27-2009 05:45 AM
Re: how to search the exact word using grep in hpux
grep -c "ze4egi\>" /etc/passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 05:48 AM
тАО05-27-2009 05:48 AM
Re: how to search the exact word using grep in hpux
The '-w' switch isn't/wasn't available in 10.20 or 11.0.
Since you are searching '/etc/passwd' you might anchor your matches with ":" like:
# grep ":ze4egi:" /etc/passwd
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 06:18 AM
тАО05-27-2009 06:18 AM
Re: how to search the exact word using grep in hpux
You need to use regexp.
you can try:
$ toto=daemon
$ egrep "[^[:alnum:]]$toto[^[:alnum:].]|^$toto[^[:alnum:].]|[^[:alnum:]]$toto$" /etc/passwd
daemon:*:1:5::/:/sbin/sh
$ toto=aemon
$ egrep "[^[:alnum:]]$toto[^[:alnum:].]|^$toto[^[:alnum:].]|[^[:alnum:]]$toto$" /etc/passwd
$
Regards,
Cedrick Gaillard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 06:20 AM
тАО05-27-2009 06:20 AM
Re: how to search the exact word using grep in hpux
if your egrep does not understand [^[:alnum:]] you can replace it with :
[^a-zA-Z0-9]
Cheers,
Cedrick Gaillard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-27-2009 07:36 AM
тАО05-27-2009 07:36 AM
Re: how to search the exact word using grep in hpux
See the below link there are so many grep examples are there
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_04_02.html
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2009 12:19 PM
тАО05-28-2009 12:19 PM
Re: how to search the exact word using grep in hpux
(instead of whitespace there is a : between the "words" - the only exception is the gecos field, it can contain whitespaces too...)
if you want to search for a particular user then either
# grep "^username:"
or use the special command pwget:
# pwget -n username
or
# awk -F: '{ if ( $1 == "username" ) print $0 }' /etc/passwd
this will print the whole line from /etc/passwd.
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2009 01:01 PM
тАО05-28-2009 01:01 PM
Re: how to search the exact word using grep in hpux
# printf '\nthis is a sample\nfor \
> what can be done\nwith sed\n\n'
this is a sample
for what can be done
with sed
# printf '\nthis is a sample\nfor \
> what can be done\nwith sed\n\n' |
> sed -n '/\s*what\s*/p'
for what can be done
#
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2009 01:05 PM
тАО05-28-2009 01:05 PM
Re: how to search the exact word using grep in hpux
sed -n '/\swhat\s/p'
without the stars it match all the words that has whitespace(s) before and after
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-28-2009 04:53 PM
тАО05-28-2009 04:53 PM
Re: how to search the exact word using grep in hpux
I suspect that your man pages do not mention -w either. The -w option was added to 11.00 or 11.11 as a 'funny' patch, that is, there didn't seem to be a grep patch but it was added with something else. grep is telling you that the option does not exist in the (old) version you are using.
As mentioned, the passwd file doesn't have words -- words being defined as text surrounded by white space. If you are searching the GECOS field (the user's name and related information), you need to isolate GECOS with something like awk and then search for words:
awk -F: '{print $5}' /etc/passwd | grep -w ze4egi
This will only work for a grep that has the -w option.
Bill Hassell, sysadmin