- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Grep question
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
08-26-2004 03:22 AM
08-26-2004 03:22 AM
Grep question
The file test contains
The word is ABC
Something ABC.orig
when i do grep ABC test|wc -l . It returns 2
Is there any way i could grep for the exact word ABC?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:26 AM
08-26-2004 03:26 AM
Re: Grep question
grep ABC test|grep -v ABC.orig | wc -l
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:28 AM
08-26-2004 03:28 AM
Re: Grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:29 AM
08-26-2004 03:29 AM
Re: Grep question
grep " ABC " test
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:31 AM
08-26-2004 03:31 AM
Re: Grep question
Else get GNU grep.
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:31 AM
08-26-2004 03:31 AM
Re: Grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:32 AM
08-26-2004 03:32 AM
Re: Grep question
just
grep " ABC" test
Regards
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:32 AM
08-26-2004 03:32 AM
Re: Grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:32 AM
08-26-2004 03:32 AM
Re: Grep question
If you want to grep for ABC as part of a line: -
grep " ABC " file (note the spaces)
If you want a line with ONLY ABC: -
grep "^ABC$" file (^ anchors start of line, $ anchors end)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:35 AM
08-26-2004 03:35 AM
Re: Grep question
grep "[ | ]ABC[ | ]" file
Where the brackets contain "space pipe tab"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:35 AM
08-26-2004 03:35 AM
Re: Grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:36 AM
08-26-2004 03:36 AM
Re: Grep question
grep -e " ABC " -e " ABC$" -e "^ABC " -e "^ABC$"
That will find:
1. ABC surrounded by spaces.
2. ABC ending a line
3. ABC starting a line
4. A line consisting only of ABC
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:37 AM
08-26-2004 03:37 AM
Re: Grep question
#man grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:39 AM
08-26-2004 03:39 AM
Re: Grep question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:50 AM
08-26-2004 03:50 AM
Re: Grep question
$ grep -x ABC test
ABC
$
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 03:53 AM
08-26-2004 03:53 AM
Re: Grep question
the grep -x ABC doesnt work as it looks for the exact line ..the lines are "The word is ABC" and "Something ABC.orig" so if i do grep -x ABC test|wc -l it returns 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:01 AM
08-26-2004 04:01 AM
Re: Grep question
If you have ABC on a line then grep -x ABC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:06 AM
08-26-2004 04:06 AM
Re: Grep question
Else get GNU grep
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:06 AM
08-26-2004 04:06 AM
Re: Grep question
grep ABC$ test works
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:23 AM
08-26-2004 04:23 AM
Re: Grep question
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:33 AM
08-26-2004 04:33 AM
Re: Grep question
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:35 AM
08-26-2004 04:35 AM
Re: Grep question
Something like:
grep "[ \t]ABC[ \t]\|[ \t]ABC$\|^ABC[ \t]\|^ABC$" test |wc -l
However, both our solutions do not give you an accurate count of no of ABCs (if more than one is present on the same line).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 04:43 AM
08-26-2004 04:43 AM
Re: Grep question
The `wc -l` does not provide a count of the number of instances of ABC, just the number of lines it is found on.
So if it present 5 times on 1 line, the return from the `wc -l` will be 1. This pattern was only found on 1 line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2004 05:02 AM
08-26-2004 05:02 AM
Re: Grep question
Search for 'grep word' gives numerous useful prior topics.
perl's \b is great for this wrok as per:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=228233
A couple of months ago I suggested:
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)
That was in topic:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=284829
hth,
Hein.