Grep in one column in Linux

I am trying to parse the output of a command df -h. For instance:

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 need values ​​only in the "Free" column. But the command awkdoes not work the way I wanted, because the number of words in each line is not the same. When I run the command df -h | awk '{print $4}', it outputs the result as follows:

Avail

58%
433M

19%
252G
3.7T
+3
source share
3 answers

Try the following:

df -Ph | awk '{ print $4 }'

Per manpage:

   -P, --portability
          use the POSIX output format

This will not result in unnecessary line breaks. hwill provide you with a readable format.

+4
source

I personally think that using the --outputoption dfis the right way:

df -h --output='avail'
+2
source

? :

df -h | grep / | awk '{print $4}'

: , ​​ 40 : enter image description here

+1

All Articles