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.
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.
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.
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