- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- The grep 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-26-2003 05:40 AM
03-26-2003 05:40 AM
I had a file test.dat which contained two lines as below:
MSC_ID
MSC_ID_LIST
Then I used "grep MSC_ID test.dat" just return
MSC_ID
MSC_ID_LIST
However I could not get the unique line that included "MSC_ID" only.
I tried :
grep "\
egrep "\
egrep '\
All failed.How could I catch the "MSC_ID" line only?
Thanks
Jack
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:46 AM
03-26-2003 05:46 AM
Re: The grep pattern?
Try this:
# grep -x MSC_ID test.dat
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:50 AM
03-26-2003 05:50 AM
Re: The grep pattern?
I tried that but also failed.
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:52 AM
03-26-2003 05:52 AM
Re: The grep pattern?
Maybe I missed other infor,in fact it is:
MSC_ID 093-234
MSC_ID_LIST 1157
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:52 AM
03-26-2003 05:52 AM
Re: The grep pattern?
Regards,
RZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:53 AM
03-26-2003 05:53 AM
Re: The grep pattern?
grep "^MSC_ID$" test.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:54 AM
03-26-2003 05:54 AM
Re: The grep pattern?
another method is matching at the end of line
grep MSC_ID$ test.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:57 AM
03-26-2003 05:57 AM
Re: The grep pattern?
MSC_ID 093-234
MSC_ID_LIST 1157
If you want the first, but not the second, then do
grep "MSC_ID " test.dat
i.e. a space after "MSC_ID". That will match "MSC_ID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 05:58 AM
03-26-2003 05:58 AM
Re: The grep pattern?
grep -v MSC_ID_LIST test.dat
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:02 AM
03-26-2003 06:02 AM
Re: The grep pattern?
And Frank,it does work as you mentioned,then what could be used when I really want to match a word precisely?
I checked the manual and they told me that the "\
Why the grep "\
Cheers
Jack
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:11 AM
03-26-2003 06:11 AM
Re: The grep pattern?
Because it is not implemented in your version of HP-UX. I.e. "the manual" you read is probably not a HP-UX manual.
There are many threads on this subject. Please search for "grep -w" and you will probably find them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:22 AM
03-26-2003 06:22 AM
Re: The grep pattern?
I'm sorry but Ross already gave you the answer :^). To match an isolated word, use -w option of grep.
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:45 AM
03-26-2003 06:45 AM
Re: The grep pattern?
I think that grep -w is only available for 11.11 and newer.
You can make use of the underscore character that follows immediately after the string MSC_ID.
The underscore belongs to the :punct: class, and you can make an unreadable regular expression that says that if such a character??comes immediately after your string, then do not match it.
Infile example:
MSC_ID 093-234
MSC_ID_LIST 1157
MSC_ID.LIST 1157
MSC_ID;LIST 1157
MSC_ID:LIST 1157
Command on my 11.0 system:
# grep -E "MSC_ID[^[:punct:]]" ./infile
MSC_ID 093-234
See e.g. man tr for other classes,
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2003 06:09 PM
03-26-2003 06:09 PM
Re: The grep pattern?
John K. is correct. The '-w' option for 'grep appears in HP-UX at 11.11. For earlier, standard HP-UX releases, we can embellish the matching to cover (more) cases, as for instance, where your token occurs anchored to the beginning or end of a line, etc. with:
# echo "MSC_ID"|grep -E -e "MSC_ID[^[:punct:]]" -e "MSC_ID$" | grep -E -e "[^[:punct:]]MSC_ID" -e "^MSC_ID"
Regards!
...JRF...