- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk problem - convert a char string to integer
Operating System - HP-UX
1821244
Members
2791
Online
109632
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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-23-2003 12:38 PM
тАО09-23-2003 12:38 PM
I'm trying to total up the size of a backup session using the omnirpt command.
Unfortunately the Size field is not constant if using " " as a delimiter because the Description field sometimes has spaces in it.
So I've grabbed the size like so:
used_kb = substr($0,123,10)
But that inserts spaces in front of the number.
So I tried getting rid of them with:
gsub(" ","",used_kb)
and it prints fine but when I total all the lines with:
total_kb = total_kb + used_kb
I get funny output:
TOTAL KB = 1.25552e+07
Is there a way to convert a line that looks something like this:
123
to an integer?
-Ronelle
Unfortunately the Size field is not constant if using " " as a delimiter because the Description field sometimes has spaces in it.
So I've grabbed the size like so:
used_kb = substr($0,123,10)
But that inserts spaces in front of the number.
So I tried getting rid of them with:
gsub(" ","",used_kb)
and it prints fine but when I total all the lines with:
total_kb = total_kb + used_kb
I get funny output:
TOTAL KB = 1.25552e+07
Is there a way to convert a line that looks something like this:
123
to an integer?
-Ronelle
rm -r /it/managers
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2003 03:25 PM
тАО09-23-2003 03:25 PM
Solution
You don't suppose that the output is simply correct perhaps? 1e07 kb would be 10,000,000 kb = 10,000 mb = 10 gb. Not unreasonable perhaps?
If the output is correct, you only have an output formatting problem. Use PRINTF to force your own method over the default.
fwiw... I sometimes use 0 + string to force an number conversion... 'just to be sure'.
# awk 'BEGIN{u=substr(" 123 ",2,6); t=u+0;print u "|" t "|"}'
123 |123|
# awk 'BEGIN{t=12345678;print t; printf ("%9d\n",t)}'
1.23457e+07
12345678
met vriendelijke groetjes,
Hein.
If the output is correct, you only have an output formatting problem. Use PRINTF to force your own method over the default.
fwiw... I sometimes use 0 + string to force an number conversion... 'just to be sure'.
# awk 'BEGIN{u=substr(" 123 ",2,6); t=u+0;print u "|" t "|"}'
123 |123|
# awk 'BEGIN{t=12345678;print t; printf ("%9d\n",t)}'
1.23457e+07
12345678
met vriendelijke groetjes,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2003 03:33 PM
тАО09-23-2003 03:33 PM
Re: Awk problem - convert a char string to integer
arghh 1:
The forum stripped my carefully places spaces, I chould have also printed a leading seperation bar "|", but I think it also converted multiple spaces before and after the " 123 " into a single space.
arghh 2: (minor), I just check Ronelle's profile and while the name suggests Holland, to registered country is New Zealand. Oh well, so much for the localized sign off. Then again...
Cheers,
Hein.
The forum stripped my carefully places spaces, I chould have also printed a leading seperation bar "|", but I think it also converted multiple spaces before and after the " 123 " into a single space.
arghh 2: (minor), I just check Ronelle's profile and while the name suggests Holland, to registered country is New Zealand. Oh well, so much for the localized sign off. Then again...
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2003 03:40 PM
тАО09-23-2003 03:40 PM
Re: Awk problem - convert a char string to integer
Thanks for the info Hein.
I'm actually from South Africa and speak afrikaans so your friendly greeting didn't go un-noticed!
I'm actually from South Africa and speak afrikaans so your friendly greeting didn't go un-noticed!
rm -r /it/managers
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP