I need help with the cut command.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 14
Reputation: Impact4ever is an unknown quantity at this point 
Solved Threads: 0
Impact4ever's Avatar
Impact4ever Impact4ever is offline Offline
Newbie Poster

I need help with the cut command.

 
0
  #1
Nov 2nd, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: baslow is an unknown quantity at this point 
Solved Threads: 0
baslow baslow is offline Offline
Newbie Poster

Try using sed

 
0
  #2
Nov 2nd, 2009
Originally Posted by Impact4ever View 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!
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,285
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 586
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #3
Nov 2nd, 2009
You could also use awk:
Shell Scripting Syntax (Toggle Plain Text)
  1. sk@svn:~/devex$ df -h | awk '{ print $1,$2,$5 }'
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC