Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awk to print line greater than zero in column 1

I am trying to print the name of directories whose free space is greater than zero.

  #Listed all the directory and their consumed space.
    du -sm storage*
    365     storage1
    670     storage2
    1426    storage3

I have threshold value of 1000M , so I am trying to print free space in these directories relative to threshold value provided.

du -sm storage* | awk -v threshold="1000" '$1>0{print $1=threshold-$1,$2}'
635 storage1
330 storage2
-426 storage3

So , I want to print those directories whose free size is positive integer. Something like :

635 storage1
330 storage2

Any correction ?

like image 204
P.... Avatar asked Oct 20 '25 11:10

P....


1 Answers

I think this got overly complicated. If you just want to check that the size is positive and lower than a given threshold, say so:

awk -v threshold=1000 '0 < $1 && $1 < threshold'

Test

$ cat file
635 storage1
330 storage2
-426 storage3

$ awk -v thr=1000 '0 < $1 && $1 < thr' file
635 storage1
330 storage2
like image 131
fedorqui 'SO stop harming' Avatar answered Oct 22 '25 02:10

fedorqui 'SO stop harming'



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!