- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk question
Operating System - HP-UX
1754020
Members
7483
Online
108811
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
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
тАО01-22-2008 04:55 PM
тАО01-22-2008 04:55 PM
I am having the output of du -xk in a file and it's showing up as this :
grep M tmp_space|more
1022M /alerts
1015M /heartbeat
987M /home/allan
983M /home/allan2
969M /home/aint.....
932K /home/aint4
I need to go away with k's ( kilo bytes ) and show only M's ( megabytes ) along with the dir listing. How do I do that. Please help.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2008 05:02 PM
тАО01-22-2008 05:02 PM
Re: awk question
Save yourself a ton of work and do a search in the Forums for a script of Bill Hassell's called "bdfmegs".
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2008 05:38 PM
тАО01-22-2008 05:38 PM
SolutionHmmm,
1) my "du -xk" does not output a K, nor an M
2) my grep for M does not return a line like "932K /home/aint4" without an M
3) do you want to just not just any line with K, or 'convert' to M? If converting, round? truncate or use decimals?
4) where is awk in this picture?
I suspect an awk script made the M/K output lines. Why not show (the critical parts) of it?
Finally, my guess for a solution... just make that grep more precise.
What's the whitespace between M and / ?
Is it a TAB as per du, or spaces?
for spaces try:
grep -E "M +\/" tmp_space
for tab try
grep -E "M[[:cntrl:]]\/" tmp_space
in perl
perl -ne 'print if /M\s+\//' tmp_space
or
perl -ne 'print if m:M\s+/:' tmp_space
cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2008 11:45 PM
тАО01-22-2008 11:45 PM
Re: awk question
If you just want to use awk to change the lines with "K" you can use:
awk '
{
len = length($1)
number = substr($1, 1, len - 1)
unit = substr($1, len, 1)
if (unit == "M")
print $0
else # assume K
printf "%.3fM %s\n", number/1024, $2
} ' tmp_space
awk '
{
len = length($1)
number = substr($1, 1, len - 1)
unit = substr($1, len, 1)
if (unit == "M")
print $0
else # assume K
printf "%.3fM %s\n", number/1024, $2
} ' tmp_space
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.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP