- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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
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
01-18-2004 11:11 PM
01-18-2004 11:11 PM
I know this may sound a bit basic but I would like to know how to use grep so that the outcome is true if and only if an EXACT match is found to a string.
Jeff
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:15 PM
01-18-2004 11:15 PM
Re: Grep question
As in
grep " Jeff Picton " somefile
?
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:17 PM
01-18-2004 11:17 PM
Re: Grep question
Yes I am aware of that but when I do say grep "e" /etc/hosts, I get every entry in the host table containing e.
I don't know why
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:22 PM
01-18-2004 11:22 PM
Re: Grep question
That's the way grep functions. If you want to be more specific, you need to do so when you specify your string.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:27 PM
01-18-2004 11:27 PM
Re: Grep question
Hi Jeff
since you are grepping for "e" in /etc/passwd, it is showing all the lines containing character "e"
man grep will explain you better.
if you don't lines without "e"
grep -v e /etc/passwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:30 PM
01-18-2004 11:30 PM
Re: Grep question
OK that fine but what about if I want to produce an error message so that the outcome of grepping a typo error for example a single character returns false unless there is a machine who is labelled e in the host file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:33 PM
01-18-2004 11:33 PM
Re: Grep question
grep "e" is perhaps a little simple for what you seem to require.
What is your actual requirement? A letter in a specific position in a line or word?
Here's a conditional check for the presence of a string in a file:
for i in $string
do
grep $i my_input_file
if [ $? -eq 0 ];then
echo $i " exists"
else
echo $i " does not exist"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2004 11:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2004 01:07 AM
01-19-2004 01:07 AM
Re: Grep question
Beginning with 11.11 you also have the '-w' option to grep a word (beginning or end of a line, or separated with 'non word' char). Also the '-x' option allows you to grep an exact string, which mean a line only composed of that string.
Regards.