LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-02-2011, 04:56 AM   #1
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Rep: Reputation: 9
Round disk space with awk


Hi,

I'm totally new to awk, and I need some help.
I want to use awk to list all the mount points, disk size and space available. Now I have all that info but I want to round the totals, so there is no delimiters, how can I do that?


PHP Code:
#!/bin/sh
date
df
=`df -Pl | grep "^/dev" | awk '{print $6, $2/1024 , $4/1024}' | sed "s/%//"`
echo 
"$df"

69549.6 55521.4
/tmp 7932.81 7371.57
/u01 49596 23313.5
/vote1 1024 741.812
/vote2 1024 741.812
/vote3 1024 741.812
/ocr 1024 505.625
/ocrmir 1024 505.625
/backup 204797 182347 
 
Old 06-02-2011, 05:15 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,292

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Hi

There is a function called int in awk, but it always rounds down, but you can add 0.5 to make it round the numbers.
Code:
df=`df -Pl | grep "^/dev" | awk '{print $6, int($2/1024+0.5) , int($4/1024+0.5) }' | sed "s/%//"`
 
1 members found this post helpful.
Old 06-02-2011, 03:43 PM   #3
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

Rep: Reputation: 197Reputation: 197
It's not clear to me exactly what you're trying to achieve, but this springs to mind:

Code:
$ df -h
 
Old 06-02-2011, 03:48 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Try the OFMT built-in variable.
 
Old 06-02-2011, 06:56 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,507

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Also awk can do the grep for you as well, simply use // construct prior to action braces.
 
Old 06-03-2011, 03:32 AM   #6
vanish78
LQ Newbie
 
Registered: May 2011
Posts: 13

Original Poster
Rep: Reputation: 9
Thank you Guttorm that did the trick
 
Old 06-03-2011, 06:10 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,507

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Please mark as SOLVED once you have a solution
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
partition space and disk space usage and free don't match nsic Linux - Newbie 3 02-22-2013 12:57 PM
Sure fire method or work-a-round to break the 137GB disk size limit edh56 Linux - Hardware 23 01-22-2011 11:07 PM
Cedega "Disk space required for the installation exceeds available disk space" Solved Spewdemon LinuxQuestions.org Member Success Stories 1 10-18-2007 06:19 PM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 03:58 PM
PS2 mouse goes crazy [it goes round n round n round...] goci Linux - Hardware 2 10-09-2003 08:15 AM


All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration