- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Grepping issues..
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
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
тАО02-27-2008 11:59 AM
тАО02-27-2008 11:59 AM
Grepping issues..
I found another problem with my disk-adding script today. When looking for disks, I use grep.
When I grep for the following disk sizes:
5242880
I also pick up these as well:
524288000
How do I specifically pick out one or the other, using grep, without resorting to the -v option?
If I can't use grep, I'll have to totally revamp the script...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 12:12 PM
тАО02-27-2008 12:12 PM
Re: Grepping issues..
You need to anchor your regular expression or modify it to fit the context you want to match.
For example:
# grep " 5242880 "
...would find matches that are bounded by a space on either side.
# grep "^5242880$"
...would demand that the string matched only if it was anchored to the beginning (^) and the end ($) of the line.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 12:47 PM
тАО02-27-2008 12:47 PM
Re: Grepping issues..
I set the disk sizes to a variable called $SIZE. How would it work with a variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 12:52 PM
тАО02-27-2008 12:52 PM
Re: Grepping issues..
# VAR=5242880
# echo " 5242880 "|grep " ${VAR} "
5242880
That is, reference the variable just like you would when you interpolate it the shell. Notice that is is good practive to encapsulate the variable name in curly braces as shown.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 01:18 PM
тАО02-27-2008 01:18 PM
Re: Grepping issues..
Here is an example of the what I am doing:
http://www.unix.com/showthread.php?p=302171123&posted=1#post302171123
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 01:26 PM
тАО02-27-2008 01:26 PM
Re: Grepping issues..
Thanks to all!
I am always open to better solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 01:38 PM
тАО02-27-2008 01:38 PM
Re: Grepping issues..
Patrick, why is this post a VERBATIM copy from another forum site? INCLUDING someone else's suggestion to use the '-w' switch of grep !!!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 02:04 PM
тАО02-27-2008 02:04 PM
Re: Grepping issues..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2008 09:39 PM
тАО02-27-2008 09:39 PM
Re: Grepping issues..
>I am always open to better solutions.
That's what I would have suggested.