The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Quick Question on sed command in shell script luft Shell Programming and Scripting 4 09-10-2008 06:36 PM
Guidance needed for quick script senthilkumar_ak UNIX for Advanced & Expert Users 4 08-08-2008 07:59 AM
quick script C shell ajp7701 Shell Programming and Scripting 1 03-18-2008 04:31 PM
Quick help needed in the Shell Script namishtiwari Shell Programming and Scripting 1 02-01-2008 09:44 AM
need a quick basic shell script help eb222 Shell Programming and Scripting 6 11-22-2007 09:00 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 11-20-2008
pobman pobman is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 31
Quick script to display df as a CSV

Hi ,

Can some one show me how to display a df -k as a CSV.

I am guessing it is something like:

Code:
df -kP /home | awk ' {print $1 "," $2 "," $3 "," $4 "," $5 "," $6} '
but it does not output correctly as the fields are not in line.
I could try to use a delimiter but there is a space in the word "Mounted On"

I have also tried
Code:
for i in `df -kP` ; do echo $i |awk ' {print $1 "," $2 "," $3 "," $4 "," $5 "," $6 "," $7 } '; done
Again with bad results.

Is their an easy way to achieve this?

UPDATE:
I have the code almost working doing this:
Code:
         COUNTLINES=0
         NUM=`df -kP |wc -l`
         COUNTLINES=`expr $COUNTLINES + $NUM - 1`
         df -kP |head -n 1| awk ' {print $1 "," $2 "," $3 "," $4 "," $5 "," $6 " " $7} '
         df -kP |tail -n $COUNTLINES| awk ' {print $1 "," $2 "," $3 "," $4 "," $5 "," $6} '
         df -kP |tail -n $COUNTLINES| awk ' {print $1 "," $2 "," $3 "," $4 "," $5 "," $6} '

Last edited by pobman; 11-20-2008 at 09:38 PM..
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0