?
Solved

using Awk or sed command

Posted on 2012-08-17
4
Medium Priority
?
473 Views
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
/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
0
Comment
Question by:07592161981m
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
mwheeler1982 earned 2000 total points
ID: 38306127
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
 
LVL 31

Expert Comment

by:farzanj
ID: 38306132
df -H /opt
0
 
LVL 5

Expert Comment

by:mwheeler1982
ID: 38306143
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
 
LVL 31

Expert Comment

by:farzanj
ID: 38306153
df -H /opt| grep '52%'

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

831 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