Search code examples
sedlinux-disk-free

Manipulate df output with sed


I have a question about sed.

Output:

Filesystem              avail
rpool/ROOT/s10_u11_201704 244719726

Wanted information:

s10_u11_201704

I tried:

df -b / | sed '1d;s/.*\/\(*\ \)\ .*/\1/g'

The \(*\ \) does not work.


Solution

  • using awk :

    df -b / |awk -F'/' 'NR>1{split($NF,a," ");print a[1]}' 
    s10_u11_201704
    

    Using sed:

    df -b / |sed -r '1d;s|(^.*)/([^ ]+).*|\2|g'
    s10_u11_201704
    

    Disclaimer: df -b is not available in any of available distros to me.