0

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.

Pang
  • 9,564
  • 146
  • 81
  • 122
M.S.
  • 485
  • 1
  • 4
  • 7
  • 1
    Note you can use `--output=source` to just print the filesystem info. See [How to select a particular column in linux df command](https://stackoverflow.com/a/28809214/1983854). – fedorqui May 31 '17 at 11:28

2 Answers2

3

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.

P....
  • 17,421
  • 2
  • 32
  • 52
  • I'm wondering because I have `df (GNU coreutils) 8.21` but no `-b` option. – John Goofy May 31 '17 at 13:09
  • I too have `df` without `-b` flag. Just mimicked for OP's understanding. – P.... May 31 '17 at 13:17
  • 2
    `-b` is trivial. The essence of the answer is how to extract the desired text. and It's rightly done in all of the available answers. I think all are correct including this. On side notes, there is a change that some proprietary Linux version may have `-b` flag. – P.... May 31 '17 at 13:25
  • also to add, it's clearly helping OP in getting his results. – P.... May 31 '17 at 13:26
1

Short awk approach:

df --output=source | awk -F'/' '{print $NF}'

  • --output=source (--output[=FIELD_LIST]) - use the output format defined by FIELD_LIST

  • -F'/' - treating / as field separator

  • $NF - the last field value

RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105