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
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!
dfin particular? If the latter, you can specify particular output fields explicitly e.g.
df --output=pcent /dev/sdb1
cuton character position on line which makes it fail when line length changes with fluctuations in file size. I believe you can tell
cutto select column
5delineated by spaces but I'm on phone and can't research and effectively post an answer.
cutwill see one column after each delimiter.