I'm trying to parse df -h command's output. For example:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGExaDb-LVDbSys1
30G 17G 12G 58% /
/dev/sda1 496M 38M 433M 8% /boot
/dev/mapper/VGExaDb-LVDbOra1
99G 18G 76G 19% /u01
tmpfs 252G 90M 252G 1% /dev/shm
dbfs-dbfs_user@:/ 4.0T 283G 3.7T 8% /dbfs_direct
I only want values under "Avail" column. But awk command doesn't work as i wanted, because number of words in each line is not the same. When i run df -h | awk '{print $4}' command, it gives the output like this:
Avail
58%
433M
19%
252G
3.7T
Try this:
df -Ph | awk '{ print $4 }'
Per man page:
-P, --portability
use the POSIX output format
This won't lead to unnecessary line breaks. h will give you in human readable format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With