0

Hi everyone,

In part of my script, I'm trying cut out couple of columns from the df -h command.

The ones I want is the Filesystem column and the Mounted On column. This is what I have so far.

df -h | cut -d " " -f1

And that will get the Filesystem in the first field, but for the next column, I tried different fields and I still keep getting a blank space.

Any help you guys can give will be greatly appreciated!
Thanks!

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sknake
0

Hi everyone,

In part of my script, I'm trying cut out couple of columns from the df -h command.

The ones I want is the Filesystem column and the Mounted On column. This is what I have so far.

df -h | cut -d " " -f1

And that will get the Filesystem in the first field, but for the next column, I tried different fields and I still keep getting a blank space.

Any help you guys can give will be greatly appreciated!
Thanks!

Well, a quick and dirty way would be to interpose a sed command which would reduce multiple spaces to just one. Then the "Mounted On" column would reliably be field 5 (assuming your df outputs in the same format as mine):

df -h | sed -e 's/[ ][ ]*/ /g' | cut -d" " -f1,5
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.