![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 05:36 PM |
| Guidance needed for quick script | senthilkumar_ak | UNIX for Advanced & Expert Users | 4 | 08-08-2008 06: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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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} '
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
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.. |
|
||||
|
If you want the output is Comma Separated Values like these :
Code:
/dev/sda2, 15519908, 4768020, 9963500, 33%, / /dev/sda5, 45042712, 30363336, 12391320, 72%, /home tmpfs, 253156, 36, 253120, 1%, /dev/shm gvfs-fuse-daemon, 15519908, 4768020, 9963500, 33%, /home/user/.gvfs /dev/sda1, 15566008, 12771972, 2794036, 83%, /media/disk Code:
df -k | tr -s " " | sed 's/ /, /g' |
|
||||
|
Awesome, I'll be making a note of that for the future.
![]() |
| Sponsored Links | ||
|
|