0

I have the result in below command. They are capacity of drives I want to compare to a threshold value. So I want to compare each line to a specific value. If greater then some condition follows.

df -kP | awk '{print $5}'| sed 's/%//g'|sed -n '1!p' 

Output of this command is like this :

36 0 19 36 36 

1 Answer 1

0

Just do it all in awk:

df -kP | awk 'NR > 1 { gsub("%","",$5); if (0 + $5 > 90) { system("echo " $6 " is too high") }}' 

Here we're manipulating $5 as you were before, but using gsub() to strip off the % sign, NR > 1 to take care of the sed, and after forcing $5 to be seen as integer, we compare it to a magic value of 90; if true, then we call out a system command (echo).

1
  • That just works fine thanks for the answer But I will be storing above command in a variable and then comparing it like this: file_usage=$( df -kP | awk '{print $5}'| sed 's/%//g'|sed -n '1!p') Commented Mar 16, 2017 at 1:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.