I want to print Use% column with all % value in 'df -k' command. I want to compare all those value to a variable value.
Asked
Active
Viewed 1,622 times
-1
-
Are you using this in an AIX environment? (I noticed the tag) – Jeff Schaller Mar 03 '17 at 01:48
-
Ankit, don't forget to accept any answer that solved your problem (as it appears Stéphane's has). Thank you! – Jeff Schaller Aug 23 '17 at 20:23
3 Answers
1
df -kP | awk 'NR>1 && $5+0 >= 90'
Would list the entries (in the portable output format of df
(with -P
) that also guarantees all entries are on a single line) for which the use%
is greater or equal to 90
. The +0
is to force numeric comparison (otherwise 100%
would be considered less than 90
).

Stéphane Chazelas
- 544,893
0
Is this what you want?
df -k|sed 's/ */\t/g;s/%//'|cut -f 5
You can then eliminate the first line and compare the values, but you have no more device relation at this point.
[EDIT:] So I was right and you need the device. So you want something like this:
for item in `df -k|sed 's/ */_/g;s/%//'|cut -d_ -f 1,5`; do
if (( ${item#*_} > 90 )); then
echo ${item%_*} has ${item#*_}%
fi
done
This is bash syntax. Adapt it for your needs.

Jeff Schaller
- 67,283
- 35
- 116
- 255

Philippos
- 13,453
-
One more question, let suppose I ran this command and I got output 10,20,30 and now I want to find that particular line which contains '20 '. and print the 'Mounted on' column of that particular line – Ankit Kushwaha Mar 02 '17 at 07:32
0
With GNU df - Untested on aix
You can have the Use% values without parsing df
output:
df --output=pcent

Zumo de Vidrio
- 1,703