awk with mulitple FS

Hi,

I would like to get 5th field from this output using FS[ %].

Filesystem 1024-blocks Used Available Capacity Mounted on
172.29.138.222:/vol/vol0 311936256 2565248 309371008 1% /tmp/test

My command is

df -kP | awk ' BEGIN { FS="[ %]" ; } { print $5 ; } '

For some reason it keeps return blank screen.

Would someone help me on this ?

Thanks.

Does this work for you?

df -kP | awk '{print "["" "$5"]" ;}'

I think you are getting that because the % is not the delimiter for every field.

If I do

df -kP | awk '{print $5}' 

I get all the capacities. What output are you looking for?

Hi,

I am expecting the output to eliminate %. That's why I place % as one of my field separator.

Thanks for the input though.

Hi,

We found something on google, and it works

df -kP | awk ' BEGIN { FS="[ %\t]+" ; } { print $5 ; } '

Or you could simply use

df -kP | awk '{ print $5 ; } ' | sed 's/%//'

as well :slight_smile: