- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- grep - searching exact pattern
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
Forums
Discussions
Discussions
Discussions
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
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
03-22-2007 10:27 PM
03-22-2007 10:27 PM
grep - searching exact pattern
Could anyone help me to search exact pattern using command "grep". -w option is not available on hp-ux 11.00. Also \
Could someone please help me on this.
Thanks,
Anil
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2007 10:30 PM
03-22-2007 10:30 PM
Re: grep - searching exact pattern
Enjoy, Have FUN! H.Merijn
- Tags:
- fgrep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2007 10:32 PM
03-22-2007 10:32 PM
Re: grep - searching exact pattern
what about grep -e ....
An alternative would be perl or awk.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2007 10:40 PM
03-22-2007 10:40 PM
Re: grep - searching exact pattern
You want to search for "words"?
The poor man's replacement for grep -w is:
$ grep -e "[[:space:][:punct:]]word[[:space:][:punct:]]"
This may not work for beginning and ending of lines so you may have to add:
-e "^word[[:space:][:punct:]]" -e "[[:space:][:punct:]]word$"
>\
This only works for vi and ex(1).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2007 10:53 PM
03-22-2007 10:53 PM
Re: grep - searching exact pattern
I have a precompiled version on my site:
http://www.cmve.net/~mbrand/greps-pa2.0.tbz
Contains GNU grep-2.5.1 (with PCRE support), agrep, and pcregrep 6.4
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2007 12:19 AM
03-23-2007 12:19 AM
Re: grep - searching exact pattern
You can try:
grep -x
-x (eXact) Matches are recognized only when the entire input line matches the fixed string or regular expression.
I'm using it on HP-UX 11i
Regards,
Vadim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 02:08 AM
03-26-2007 02:08 AM
Re: grep - searching exact pattern
I have tried options -F, -x , still doesn't solve my issue. Since my server is in Production, its difficult to install the grep utility.
my requirement is to search pattern "exit"(exactly the same, should not be "#exit") in a file. It can be at any position in the file.
Please guide me..
Thank you,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 02:39 AM
03-26-2007 02:39 AM
Re: grep - searching exact pattern
If you want to use 'grep' then Dennis's approach will being you the closest to your needs.
However, you need to _define_ what you mean by a "word". Perl offers one easy way to do this. For example to find the token "localhost" in '/etc/hosts' without regard to case and bracketed by non-word characters (including line endings or beginnings):
# perl -nle 'print if /\blocalhost\b/i' /etc/hosts
If you want case-sensitivity, drop the "i" from the pattern to match.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 03:21 AM
03-26-2007 03:21 AM
Re: grep - searching exact pattern
Just put it in your own $HOME/bin or so.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 06:20 AM
03-26-2007 06:20 AM
Re: grep - searching exact pattern
If you feel that this issue is resolved go-ahead and assign points for the people who have helped you that is a nice way to show gratitude for the people who helped you. You have assigned points only to 3 of 40 responses.
Rgds
HGN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 12:50 PM
03-26-2007 12:50 PM
Re: grep - searching exact pattern
Mine would select #exit since I'm only looking for "words". You can always pipe my output into grep -v and remove "#exit" and all other false positives until you get closer to what you want.
grep -w also finds "#exit".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 05:25 PM
03-26-2007 05:25 PM
Re: grep - searching exact pattern
grep 'exit' /some/file
looks for the four letter string "exit" and displays all the lines where it appears anywhere on the line. In effect, it's the same as:
grep '.*exit.*' /some/file
If you want to restrict the matching to something that is on the beginning of line, you must anchor the beginning of the match, like this:
grep '^exit' /some/file
'^' means "beginning of line".
If you want to match something at the end of line, there is a different anchor for that:
grep 'exit$' /some/file
If you want to match when your pattern covers the entire line (i.e. the matching text is the only thing on the line), use both anchors together:
grep '^exit$' /some/file
This searches for lines that have *only* the word "exit" and nothing else.
Note that I'm using single quotes around the pattern: this way there will be no problems with special characters like "$".
If you need to use environment variables within your pattern string, you should use double quotes instead. Then you may need to replace the end-of-line anchor "$" with "\$" so the shell does not think you're specifying a variable name.
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2007 05:45 PM
03-26-2007 05:45 PM
Re: grep - searching exact pattern
Note: This isn't needed if you are using a real shell. This is only needed if you are using the scummy C shell.
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2007 09:13 PM
03-31-2007 09:13 PM
Re: grep - searching exact pattern
Try this
grep -F -x exit filename
will exactly match the string "exit" from the filename.
Regards,
Rasheed Tamton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2007 09:50 PM
03-31-2007 09:50 PM
Re: grep - searching exact pattern
I did not test with the multiword lines. It is only applicable to single word lines as already mentioned.
Regards,
Rasheed Tamton.