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
/dev/mapper/backup-BKUP
                        15G    12G   1.9G  87% /bkup
/dev/mapper/system-HOME
                       2.4G   451M   1.8G  21% /home
/dev/mapper/system-OPT
                        33G    16G    15G  52% /opt
/dev/mapper/system-TMP
                       4.3G   322M   3.7G   9% /tmp
/dev/mapper/system-USR
                       3.7G   2.8G   781M  78% /usr
/dev/mapper/system-VAR
                       1.1G   435M   570M  44% /var
159.83.9.102:/nfs/software
                       143G    95G    41G  71% /mnt/software
doc.its.co:/bkup
                       349G   188G   161G  54% /mnt/upgdp
prt.co:/home/appdsadmin/DataSource
                       2.5G   232M   2.1G  11% /mnt/datasource
07592161981mAsked:
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
0
 
farzanjCommented:
df -H /opt
0
 
mwheeler1982Commented:
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.
0
 
farzanjCommented:
df -H /opt| grep '52%'

Open in new window

0
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.