Output to csv contains quotes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output to csv contains quotes
# 8  
Old 07-25-2013
Can't use notepad++ as I'm not having a windows computer. And, why use that in the first place? csv is designed to be used in spread sheets and data bases, so feed it into one of those... Again, use awk (which you use anyhow) to place the comma separators and the \r\n into the file at the right places, and I guess, it will fly.
# 9  
Old 09-06-2013
Output to csv contains quotes *FINAL*

RudiC thank you for all of your input.

Here is the completed set of codes. Note that I have included both AIX and Linux versions. I also have screen and email output sections combined for space saving. Let me know if you have any ideas on making this more usable. Currently, in our enterprise, it is extremely difficult to incorporate cron tasks, since we use another vendor for those type tasks, which disables cron functionality. SO I just copy/paste when I need to use any part of it.

So here it is.

Code:
#!/bin/ksh
# AIX Version 1.0 by Stryker Cain.
# With assistance from Sujith Achutan
# Jeyagopal Dharmalingham Daniel Thornton and Jamie Banas
## Comment out the top df portion to only get a csv report emailed to you. ##
## Comment out the bottom df portion to only get a script output ##
## Leave as is to get both screen output and emailed csv report ##
## Future parameters will be to add input of email address ##
cd /tmp
HOST1=$(hostname)
df -Pg | awk 'BEGIN{
print "\t SPACE OF IMPORTANT FILE SYSTEMS on '$HOST1'\t\n----------------------------------------------------------------------\nFILE-SYSTEM\t TOTAL-SPACE\t USED-SPACE\t FREE-SPACE\t %USED\n"}
function disp(v1,v2,v3,v4,v5){
printf "%-10s\t %-10s\t %-10s\t %-10s\t %-6s \n",v1,v2,v3,v4,v5
}
NR>2&&(($3>($2*.80)&&disp($6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp($6,$2,$3,$4,$5))||($3<($2*.40)&&disp($6,$2,$3,$4,$5)))
END{print "----------------------------------------------------------------------\n "}'
df -Pg | awk 'BEGIN{
print "FILE_SYSTEM,TOTAL_GB,USED_GB,FREE_GB,PERCENT_USED"}
function disp(v1,v2,v3,v4,v5){
printf "%-1s,%-1s,%-1s,%-1s,%-1s\n",v1,v2,v3,v4,v5
}
NR>2&&(($3>($2*.80)&&disp($6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp($6,$2,$3,$4,$5))||($3<($2*.40)&&disp($6,$2,$3,$4,$5)))
END{print "'$HOST1'-\n"}' > $HOST1-df_All.csv
uuencode $HOST1-df_All.csv $HOST1-df_All.csv | /bin/mailx -s "$HOST1 diskusage script by Stryker Cain" "email address"
rm -rf $HOST1-df_All.csv
 
#!/bin/ksh
# Linux Version 1.0 by Stryker Cain.
# With assistance from Sujith Achutan
# Jeyagopal Dharmalingham, Daniel Thornton and Jamie Banas
## uuencode must be installed for this script (bottom half) to work. ##
## If not you have to comment out the uuencode part and change ##
## the mailx to the cat mail command ##
## Comment out the top df portion to only get a csv report emailed to you. ##
## Comment out the bottom df portion to only get a script output ##
## Leave as is to get both screen output and emailed csv report ##
## Future parameters will be to add input of email address ##
cd /tmp
HOST1=$HOSTNAME
df -Ph | awk 'BEGIN{
print "\t SPACE OF IMPORTANT FILE SYSTEMS on '$HOST1'\t\n----------------------------------------------------------------------\n FILE-SYSTEM\t TOTAL-SPACE\t USED-SPACE\t FREE-SPACE\t %USED\n"}
function disp(v1,v2,v3,v4,v5){
printf "%-10s\t %-10s\t %-10s\t %-10s\t %-6s \n",v1,v2,v3,v4,v5
}
NR>2&&(($3>($2*.80)&&disp($6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp($6,$2,$3,$4,$5))||($3<($2*.40)&&disp($6,$2,$3,$4,$5)))
END{print "----------------------------------------------------------------------\n "}'
HOST1=$HOSTNAME
df -Ph | awk 'BEGIN{
print "FILE_SYSTEM,TOTAL_GB,USED_GB,FREE_GB,PERCENT_USED"}
function disp(v1,v2,v3,v4,v5){
printf "%-1s,%-1s,%-1s,%-1s,%-1s\n",v1,v2,v3,v4,v5
}
NR>2&&(($3>($2*.80)&&disp($6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp($6,$2,$3,$4,$5))||($3<($2*.40)&&disp($6,$2,$3,$4,$5)))
END{print "'$HOST1'-\n"}' > $HOST1-df_All.csv
uuencode $HOST1-df_All.csv $HOST1-df_All.csv | /bin/mailx -s "$HOST1 UNIX diskusage script by Stryker Cain" "email address"
# cat $HOST1-df_All.csv | /bin/mail -s "$HOST1 UNIX diskusage script by Stryker Cain" "email address"
rm -rf $HOST1-df_All.csv


Last edited by Don Cragun; 09-06-2013 at 08:04 PM.. Reason: CODE tags; not ICODE tags for multi-line segments
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

2. Shell Programming and Scripting

Shell script that should remove unnecessary commas between double quotes in CSV file

i have data as below 123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi" i need an output to be 123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Discussion started by: mathias23
5 Replies

3. Shell Programming and Scripting

How to delete the commas in a .CSV file that are enclosed in a string with double quotes?

Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote. Please see the sample file as below: column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Discussion started by: dhruuv369
8 Replies

4. Shell Programming and Scripting

Convert csv to pipe delimited except the ones in double quotes

I have a csv data file : A,B,C,D,"A,B",E,"GG,H" E,F,G,H,I,J,"S,P" I need to replace all "," with "|" except the ones between double quotes i.e A|B|C|D|"A,B"|E|"GG,H" E|F|G|H|I|J|"S,P" CAn someone assist? (8 Replies)
Discussion started by: Shivdatta
8 Replies

5. Shell Programming and Scripting

HELP with AWK or SED. Need to replace the commas between double quotes in CSV file

Hello experts, I need to validate a csv file which contains data like this: Sample.csv "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 I just need to check if all the records contain exactly the number of... (5 Replies)
Discussion started by: shell_boy23
5 Replies

6. Shell Programming and Scripting

Excel CSV with Double Quotes and Carriage Returns

Hi List, I am sure this issue must have been encountered before. I have saved an excel CSV and sent it to my linux box where I require to parse it as a CSV line by line. The file displays fine in Excel with csv headers and consistent records and fields. However when I look at it in linux I see... (2 Replies)
Discussion started by: landossa
2 Replies

7. Shell Programming and Scripting

adding quotes around each column in a csv file

I saved the csv file in a comma delimited format. Sample input input.csv 1 abc 2 2 def 4 3 ghi 6 4 jkl 8 5 mno 10 output.csv should look like this with single quotes around each field '1' 'abc' '2' '2' 'def' '4' '3' 'ghi' '6' '4' 'jkl' '8' '5' 'mno' '10' Please help me :confused:... (3 Replies)
Discussion started by: melannie
3 Replies

8. Shell Programming and Scripting

Replacing comma with in double quotes in a csv file

Hello, I need to read a csv file and I am trying to replace a comma with a text DSEE?DSEE. Example Input "Chapter","NewTrains, "oldTrains","Delayed",10,"London" "Chapter","Newbuses,oldbuses","On Time",20,"London" Output "Chapter","NewTrainsDSEE?DSEE... (5 Replies)
Discussion started by: venkatvani
5 Replies

9. Shell Programming and Scripting

Fix CSV file with column missing quotes

I have a CSV file that is missing quotes around a column that contains text with commas. Example: Column1, Column2, Column3, Column4, Column5, Column6 Data1, Data2, Data3, Data, 4, Data5, Data6 Data1, Data3, Data3, Data, text, 4, Data5, Data6 I think the easiest way for me to fix this is to... (2 Replies)
Discussion started by: EmptyH
2 Replies

10. Shell Programming and Scripting

replace value with double quotes of specific coulmn value in csv file

Hi, I am trying to replace a specific column values in a csv file with double quotes. Example: SNO,NAME,ZIPCODE,RANK 1,Robert,74538,12 2,Sam,07564,13 3,Kim, Ed,12345,14 Desired Output: SNO,NAME,ZIPCODE,RANK 1,Robert Ken,74538,12 2,Sam Mik,"07564",13 3,"Kim, Ed",12345,14 I... (3 Replies)
Discussion started by: techmoris
3 Replies
Login or Register to Ask a Question