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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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..