944,103 Members | Top Members by Rank

Ad:
Nov 2nd, 2009
0

I need help with the cut command.

Expand Post »
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.

Shell Scripting Syntax (Toggle Plain Text)
  1. 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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Impact4ever is offline Offline
14 posts
since Jan 2008
Nov 2nd, 2009
0

Try using sed

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.

Shell Scripting Syntax (Toggle Plain Text)
  1. 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):

Shell Scripting Syntax (Toggle Plain Text)
  1. df -h | sed -e 's/[ ][ ]*/ /g' | cut -d" " -f1,5
Reputation Points: 10
Solved Threads: 0
Newbie Poster
baslow is offline Offline
2 posts
since Oct 2009
Nov 2nd, 2009
0
Re: I need help with the cut command.
You could also use awk:
Shell Scripting Syntax (Toggle Plain Text)
  1. sk@svn:~/devex$ df -h | awk '{ print $1,$2,$5 }'
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Counter
Next Thread in Shell Scripting Forum Timeline: Uix Script Help Need





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC