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!

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

You could also use awk:

sk@svn:~/devex$ df -h | awk '{ print $1,$2,$5 }'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.