- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to compare 2 numbers from a string
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
09-20-2005 05:15 AM
09-20-2005 05:15 AM
I need to check filesystem used and free space, so I want to get percentage and compare it with a value.
Script I'm using doesn't work fine in some cases due data I get from system is a string (ie, in case of percentage is 9, for my script it's greater than 85):
bdf -l|tail +2|awk 'substr($5,1,length($5)-1) > 85 && $6 == "/FAR/oracle/arch" {print}'
Is there any way to change format to an integer or to change ">" for any other command?
Thanks in advance,
Carles
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 05:41 AM
09-20-2005 05:41 AM
Re: How to compare 2 numbers from a string
Oops, I dropped the chop of the "%":
# bdf -l|tail +2|awk '{n=substr($5,1,(length($5)-1));n=n+0;if (n > 85 && $6 == "/FAR/oracle/arch" {print}}'
You could also eliminate the extra process (the 'tail':
# smhmso # bdf -l|awk '{NR>2;n=substr($5,1,($length($5)-1));n=n+0;if (n > 85 && $6 == "/FAR/oracle/arch" {print}}'
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:02 AM
09-20-2005 06:02 AM
Re: How to compare 2 numbers from a string
I would let awk do more work:
bdf -l| awk '/arch$/{sub(/%/,"",$5); if ((0+$5)>85){print}}'
Here tail is replaced by awk just lookinf for a line ending in 'arch'.
You can extent that to \/FAR\/oracle\/arch$ if need be.
It then replaces the % in $5 with nothing, converts to numeric and compares.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:21 AM
09-20-2005 08:21 AM
Re: How to compare 2 numbers from a string
If that's the case then your script will not be able to parse, compare and print the filesystems that are exceeding your "> 85" criteria. You need to modify your script as:
# bdf -l | awk 'NR!=1 && NF!=1 && substr($(NF-1),1,length($(NF-1))-1) > 85 && $6 == "/FAR/oracle/arch" {print}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:24 AM
09-20-2005 08:24 AM
Re: How to compare 2 numbers from a string
# bdf -l | awk 'NR!=1 && NF!=1 && substr($(NF-1),1,length($(NF-1))-1) > 85 && $NF == "/FAR/oracle/arch" {print}'
regards!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:48 AM
09-20-2005 08:48 AM
Re: How to compare 2 numbers from a string
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 11:38 AM
09-20-2005 11:38 AM
Re: How to compare 2 numbers from a string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:59 PM
09-20-2005 06:59 PM
Re: How to compare 2 numbers from a string
Thanks to all!