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} '