LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-20-2008, 06:50 PM   #1
pobman
Member
 
Registered: Jun 2005
Location: Wellington, New Zealand
Distribution: Fedora 9
Posts: 31

Rep: Reputation: 16
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:

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"

Is their an easy way to achieve this?

Last edited by pobman; 11-20-2008 at 07:02 PM.
 
Old 11-20-2008, 07:09 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
You pretty much had it but.

I've adjusted it as follows:
Code:
df -kP /home | awk '{print $1","$2","$3","$4","$5","$6" "$7}'
First I took out all your unnecessary spaces.
Second I put the literal commas surround by quotes between each of the first 6 fields.
Last I inserted a space with quotes around it between field 6 and 7. This makes it print the "Mounted on" as single field in your CSV. It works for the subsequent lines as well because there is no field 7 so it just outputs field 6 for the actual /home line followed by an extra space which doesn't hurt the CSV for when you open it in MS-Excel.

When I ran that on one of my RHEL5 systems it resulted in:
Quote:
Filesystem,1024-blocks,Used,Available,Capacity,Mounted on
/dev/mapper/VolGroup00-LogVol03,2063763,84550,1874356,5%,/home
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Need help create a bash script to edit CSV File imkornhulio Programming 13 02-05-2009 10:23 AM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
php mail script csv UMG:Chicken_Soüp Programming 3 02-13-2008 06:24 PM
Script to convert csv 2 xls or odt xowl Linux - Software 1 01-16-2007 09:06 PM
Shell script to read from csv file hendemeg Programming 1 05-11-2004 08:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration