How can I grep or cut the "173G" under "Verf"?
I need this for Unix scripting in school.
jonas@jonaspc:~/$ df -h /dev/sda2
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/sda2 293G 121G 173G 42% /media/Windows
|
|
|
The most comfortable solution for such task is
Or if more partitions are listed, you can pick the right line by the mount point:
Is also simple with
That supposes GNU
|
||||
|
|
|
If you must use grep and cut, you can do the following:
But this is pretty ugly, since you have to count the spaces (-f14) and the reason @manatwork used awk. You could use
Alternatively, newer grep supports outputing only a partial match and you can use that in combination with a bash trick:
The regex could be safer, but this will find all the size fields and output them one per line, while cut selects the second. |
|||||||
|
|
All other answers here are great, but if you use Bash, there is no need to use external programs such as awk, sed, grep, cut etc. The following line will do what you want:
"$av" will be the available size on /dev/sda1 If you want to use only the numeric part of "$av" ( e.g 123 in 123G ), you can use Parameter Expansion to trim the irrelevant part like that:
or just |
||||
|
|
|
If it doesn't have to be
|
|||
|
|