using Awk or sed command

Posted on 2012-08-17
Last Modified: 2012-08-17
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
Question by:07592161981m
    LVL 5

    Accepted Solution

    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
    LVL 31

    Expert Comment

    df -H /opt
    LVL 5

    Expert Comment

    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.
    LVL 31

    Expert Comment

    df -H /opt| grep '52%'

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
    Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now