Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Use awk to compare values piped from df

Use awk to compare values piped from df

Use awk to compare values piped from df

I want to use awk to compare values piped from "df" like so:


CODE -->

Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda1      725649232 118249576 571080120  18% /
udev             2994044         4   2994040   1% /dev
tmpfs            1201132      1120   1200012   1% /run
none                5120         0      5120   0% /run/lock
none             3002824       352   3002472   1% /run/shm
/dev/sr0         5487686   5487686         0 100% /media/UDF Volume 

Then pull out the red values:


And run a comparison:

if 2994040 > 1200012 then:
echo "udev exceeds tmpfs in size"
else echo "udev is smaller than tmpfs in size"

Something like that. I've gotten this far:

CODE -->

 awk '{print $c}' c=${1:-2} 

I put the above into "colmn" and then ran:

df | ./column which outputs:



I don't know how to grab the values I want, and I don't want to use cut. I want it to be smart enough to read the lines that go with udev or tmpfs (or whatever lines I specify). I imagine that if I can grab the values then I can store them in variables somehow and then run some comparison logic, but I don't know how to put it all together.


RE: Use awk to compare values piped from df


CODE --> command-line

df | awk '$1=="udev"||$1=="tmpfs"{s[$1]+=$4}END{printf"udev %s tmpfs in size",(s["udev"]>s["tmpfs"])?"exceeds":"is smaller than"}' 
Tested with gawk and mawk.

Note that on my machine there are 7 tmpfs entries in df's output, so I put my code to add them and compare the sums.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close