using Awk or sed command

Hi Experts, here is the output from df -H command. How can i filter and get only /opt and 52% in the output

Filesystem             Size   Used  Avail Use% Mounted on
/dev/dasda1            2.5G   249M   2.1G  11% /
devtmpfs               2.0G   226k   2.0G   1% /dev
tmpfs                  2.0G    25k   2.0G   1% /dev/shm
                        15G    12G   1.9G  87% /bkup
                       2.4G   451M   1.8G  21% /home
                        33G    16G    15G  52% /opt
                       4.3G   322M   3.7G   9% /tmp
                       3.7G   2.8G   781M  78% /usr
                       1.1G   435M   570M  44% /var
                       143G    95G    41G  71% /mnt/software
                       349G   188G   161G  54% /mnt/upgdp
                       2.5G   232M   2.1G  11% /mnt/datasource
Who is Participating?
mwheeler1982Connect With a Mentor Commented:
Not necessarily sed/awk, but this will work:

df -h |grep \/opt | tr -s ' ' | cut -f 5-6 -d' '

Open in new window

cut -f 5 for only the percentage, cut -f 6 for only the filesystem
df -H /opt
This will do it with awk:

df -h |grep \/opt | awk -F' ' '{ print $4 " " $5}'

Open in new window

That's more elegant than my first solution.
df -H /opt| grep '52%'

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.