Given the following substring given obtained from the command df /dev/sdb1 | tail -n 1
:
/dev/sdb1 1952971772 1441131032 511840740 74% /media/kaiman/ShareData
I'd like to extract 1952971772
and 74%
from that string, to use it in a bash script.
I know I could use some cut commands or something, but it won't work anymore if a size changes, for example.
I also had thoughts about using a regex or something, but I'd like to have the most recommended approach.
Thanks in advance!
df
in particular? If the latter, you can specify particular output fields explicitly e.g.df --output=pcent /dev/sdb1
cut
on character position on line which makes it fail when line length changes with fluctuations in file size. I believe you can tellcut
to select column2
and column5
delineated by spaces but I'm on phone and can't research and effectively post an answer.cut
will see one column after each delimiter.