awk print used space

Hi Team,

Can you please tell me how to get a used space in KB LINUX and free space in KB separate commands.

For example:

 
$df -k
/rer (apdfp01.xxx.com:/var/adm/rash/MT) : 2066900 total allocated Kb
4579 free allocated Kb
16121 used allocated Kb
89 % allocation used
/dev/deviceFS1 (D1FS ) : 0 total allocated Kb
0 free allocated Kb
0 used allocated Kb
100 % allocation used
/aeps/opt/best1 (/dev/bgsroot/lvbt1 ) : 518871 total allocated Kb
94695 free allocated Kb
42176 used allocated Kb
82 % allocation used
/aeps/opt/bmc (/dev/bgsroot/lvbc1 ) : 501828 total allocated Kb
3123 free allocated Kb
12705 used allocated Kb
31 % allocation used
/home (/dev/bgsroot/lvhme ) : 2202 total allocated Kb
7811 free allocated Kb
12391 used allocated Kb
63 % allocation used

How to print used space alone from this above output.
How to print free space alone from this above output.

Thanks in Advance,
Indu

---------- Post updated at 03:47 PM ---------- Previous update was at 02:57 PM ----------

For example:

$  df -k | grep -v Use | grep -v none | awk '{ gsub(/.*: |Kbytes.*/,x) } 1'
                                              20690 total allocated Kb
                                                    45579 free allocated Kb
                                                   161321 used allocated Kb
                                                        78 % allocation used
                                                         0 total allocated Kb
                                                         0 free allocated Kb
                                                         0 used allocated Kb
                                                       100 % allocation used
                                              5256 total allocated Kb
                                                     922 free allocated Kb
                                                    471934 used allocated Kb
                                                     91% allocation used
                                              501828 total allocated Kb
                                                    349119 free allocated Kb
                                                    152709 used allocated Kb
                                                        31 % allocation used
                                              512431 total allocated Kb
                                                    179267 free allocated Kb
                                                    333164 used allocated Kb
                                                        66 % allocation used
                                             984125 total allocated Kb
                                                    966888 free allocated Kb
                                                     17237 used allocated Kb
                                                         2 % allocation used

How to get the used allocated Kb and free allocated Kb
separately.

Thanks in Advance,
Indu

---------- Post updated at 03:59 PM ---------- Previous update was at 03:47 PM ----------

can any one pls reply back to this issue

What is the output you are expecting?

As my understanding of the question below should work ok for you.

 df -k | grep -v Use | grep -v none | awk '{ gsub(/.*: |Kbytes.*/,x) } 1' | sed -n '
/total allocated Kb/ { h ; n ; H; n; H ; x;p; }' 

If you want to get only free and used allocation info,

 df -k | grep -v Use | grep -v none | awk '{ gsub(/.*: |Kbytes.*/,x) } 1' | sed -n '
/total allocated Kb/ { h ; n ; h; n; H ; x;p; }' 

Hi,

I should get the Output for used allocated kb alone from this disk space.

For Example if i give command for Used space it should display only Used space alone:

$df -k

/rer                   (apdfp01.xxx.com:/var/adm/rash/MT) :   2066900 total allocated Kb
                                                              4579 free allocated Kb
                                                              16121 used allocated Kb
                                                              89 % allocation used
/dev/deviceFS1         (D1FS                 )    :           0 total allocated Kb
                                                              0 free allocated Kb
                                                              0 used allocated Kb
                                                              100 % allocation used
/aeps/opt/best1        (/dev/bgsroot/lvbt1   )    :           518871 total allocated Kb
                                                              94695 free allocated Kb
                                                              42176 used allocated Kb
                                                              82 % allocation used
/aeps/opt/bmc          (/dev/bgsroot/lvbc1     )  :           501828 total allocated Kb
                                                              3123 free allocated Kb
                                                              12705 used allocated Kb
                                                              31 % allocation used
/home                  (/dev/bgsroot/lvhme    ) :             2202 total allocated Kb
                                                              7811 free allocated Kb
                                                              12391 used allocated Kb
                                                              63 % allocation used

total allocated kb, free allocated Kb, used allocated Kb, allocation used are in same columns. Am unable get the used allocated kb separately from disk space.

Can you please help me in this.

Thanks in Advance,
Indu

Something like this:

$ data_to_fetch='free allocated Kb'

$ df -k | awk -v f="$data_to_fetch" '$0 ~ f' 

Define your own , needed variable to fetch the corresponding data.

based on your input:

 awk '/total allocated/ { TOAL=TOAL+$(NF-3) } /free allocated/ { FRAL=FRAL+$1; }
/used allocated/ { USAL=USAL+$1; }
END { printf("TOTAL Allocated:%s KB ,USED Allocated: %s KB,FREE Allowcated:%s KB\n",TOAL,USAL,FRAL) }' filename
TOTAL Allocated:3089801 KB ,USED Allocated: 83393 KB,FREE Allowcated:110208 KB

As you obdurately refuse to post your desired output, I can only guess you want the file system plus the allocated kBs:

df -k | awk '/:/ {printf "%s: ", $1} /used allo/ {print $(NF-3)}' file
/rer: 16121
/dev/deviceFS1: 0
/aeps/opt/best1: 42176
/aeps/opt/bmc: 12705
/home: 12391