FORMAT OF CSV FILE under unix environment.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FORMAT OF CSV FILE under unix environment.
# 29  
Old 06-23-2007
yes. i need to send this report excel sheet to outside group of people.
i tried this. still when i open the excel still it is showing default column widht.
that is why i need some thing with awk command script before send the e-mail.
i tried this script some one provided in this form.
after i run the script the report is blank.
awk 'BEGIN{
FS=","
print "<HTML><BODY><TABLE>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
print "</TABLE></BODY></HTML>"
}
'Report.csv > Report11.xls

the only solution is i think some thing i need to do with unix commands format.
# 30  
Old 06-27-2007
no body replied to me yet. pl help to fix the problem.
i tried with solutions provided in the post. but it not working the way i want.
pl see this. I really appreciate.
i have a report.csv file from oracle datavase
In that file data is like this with report heading and date

Code:
SALES DAILY REPORT
DATE: 06-26-2007 
REPORT NAME: SALES DATA

AA.BB.CCCC.DDDD,BBBBB,06-26-2007,0,BEGIN,END
ZZ.VV.DDDD.XXXXXXX,MMMMMM,06-25-2007,18,BEGIN,END
CC.XX.VVV.QQ,KKKKK,06-24-2007,END,BEGIN

fields are separated with ",".
i want to read this file create new file with new format.

i want
col1 WIDTH should increse 15 positions with spaces right side
col2 WIDTH should increse 10 positions with spaces right side
col3 WIDTH should increse 5 positions with spaces right side
col4 WIDTH should increse 7 positions with spaces right side
col5 WIDTH should increse 7 positions with spaces right side
col6 WIDTH should increse 6 positions with spaces right side
BUT HEADING OF THE REPORT SHOULD NOT BE CHANGED.

I WANT NEW OUTPUT FILE SHOULD BE LIKE THIS


Code:
SALES DAILY REPORT
DATE: 06-26-2007 
REPORT NAME: SALES DATA

AA.BB.CCCC.DDDD          ,BBBBB     ,06-26-2007   ,0   ,BEGIN   ,END
ZZ.VV.DDDD.XXXXXXX        ,MMMMMM     ,06-25-2007,18  ,BEGIN   ,END
CC.XX.VVV.QQ      ,KKKKK    ,06-24-2007       ,15     ,END    ,BEGIN

Thanks for your help
i need answer desparately.
N.
# 31  
Old 06-27-2007
PHP

Quote:
SIMPLE RULES OF THE UNIX FORUMS:
(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.
Try this :
Code:
awk -F, '
   NF <= 1 { print ; next}
   {
      print $1 "               ," \
            $2 "          ,"      \
            $3 "     ,"           \
            $4 "       ,"         \
            $5 "       ,"         \
            $6 "      ";
   }
' report.csv

# 32  
Old 06-27-2007
Not sure why you can't get the previously posted code to work.
Here's what happens when I run it, with your latest csv file, at the ksh prompt...
Code:
$ cat report.csv
SALES DAILY REPORT
DATE: 06-26-2007
REPORT NAME: SALES DATA

AA.BB.CCCC.DDDD,BBBBB,06-26-2007,0,BEGIN,END
ZZ.VV.DDDD.XXXXXXX,MMMMMM,06-25-2007,18,BEGIN,END
CC.XX.VVV.QQ,KKKKK,06-24-2007,END,BEGIN

$ awk 'BEGIN{
        FS=","
        print "<HTML><BODY><TABLE border=1>"
     }
     {
        printf "<TR>"
        for(i=1;i<=NF;i++)
          printf "<TD>%s</TD>", $i
        print "</TR>"
     }
     END{
        print "</TABLE></BODY></HTML>"
     }
     ' report.csv > report.xls

$ cat report.xls
<HTML><BODY><TABLE border=1>
<TR><TD>SALES DAILY REPORT</TD></TR>
<TR><TD>DATE: 06-26-2007 </TD></TR>
<TR><TD>REPORT NAME: SALES DATA</TD></TR>
<TR></TR>
<TR><TD>AA.BB.CCCC.DDDD</TD><TD>BBBBB</TD><TD>06-26-2007</TD><TD>0</TD><TD>BEGIN</TD><TD>END</TD></TR>
<TR><TD>ZZ.VV.DDDD.XXXXXXX</TD><TD>MMMMMM</TD><TD>06-25-2007</TD><TD>18</TD><TD>BEGIN</TD><TD>END</TD></TR>
<TR><TD>CC.XX.VVV.QQ</TD><TD>KKKKK</TD><TD>06-24-2007</TD><TD>END</TD><TD>BEGIN</TD></TR>
</TABLE></BODY></HTML>

When I open the report.xls in Excel, all of the columns are displayed correctly with column widths set to the right size.
# 33  
Old 06-28-2007
Hi Ygor,
Excellant.I really apprciate this.You have done excellant job done.
it is working now. when i open excel all the columns are comming right way.
Thank you so much. it is great help. Thanks for everybody who took time
on this thread. Thank each and every one .
thx
N.
# 34  
Old 07-07-2007
Hi Ygor,
Small clarification.
In the other report
i have first column length is 45 postions.
When i run this above scirpt, first column after 27 positions it wrapped
into next line.rest of the columns are coming is ok. rest of column are not that
big. why it wrapped into 2 lines insated of showing into single line in excel.
why it is not coming into single line.
how can i increse first column length only.
Thanks,
N.
# 35  
Old 07-08-2007
The code that I posted would not have caused the line to wrap. Perhaps try looking at the input file to see if it is already wrapped.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change date format in am/pm in csv files using UNIX

Hi All, I'm new to forum good to hear all. I stuck in converting date format in csv file using unix csv file contains as below ,750,0000000000000000GCJR, ,06/22/2016 14:48:44 I want to convert into as below ,750,0000000000000000GCJR, ,06/22/2016 02:48:44 PM Please reply asap..... (22 Replies)
Discussion started by: Raghureds
22 Replies

2. Shell Programming and Scripting

UNIX command output in csv format

I'm just wondering is there any way to capture the output of a unix command in a csv format. df -h gives the result of filesystem,free space,Used space, use %,mounted on. Is there a way to capture the command output and format it as comma sparated or fixed length file. (3 Replies)
Discussion started by: anita81
3 Replies

3. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

4. Shell Programming and Scripting

Format csv file

Hi, I need to make some changes in a csv file using awk or perl. Unfortunately, all my attempts have led to nothing so I hope you guys can help me. I have the following example input file including header(original file has 35 fields): ABC: DE Time: 2012/09/07... (3 Replies)
Discussion started by: Subbeh
3 Replies

5. UNIX Desktop Questions & Answers

Format csv file using Unix

Hi All, I have an csv file with three rows, where first containing header deatils. is there any way to make the first row to appear bold using UNIX command. Input File: Name Rank arun 1 babu 2 Expected Output: Name Rank arun 1 babu 2 (7 Replies)
Discussion started by: arunmanas
7 Replies

6. Shell Programming and Scripting

Retaining the Unix CSV format in Excel format while exporting

Hi All, I have created a Unix Shell script whch creates a *.csv file and export it to Excel. The problem i am facing is that Users wants one of the AMOUNT field in comma separted values. Example : if the Amount has the value as 3000000 User wants to be in 3,000,000 format. This Amount format... (2 Replies)
Discussion started by: rawat_me01
2 Replies

7. Shell Programming and Scripting

Display o/p in HTML format from unix environment

Hi, i want to disply the o/p in HTML format from unix environment. Let me explain my requirement. First an automated email should be sent in HTML format. The report contains number of error on a daily basis for this week. email looks like below, 01-04-2010 1000 02-04-2010 ... (3 Replies)
Discussion started by: apsprabhu
3 Replies

8. Shell Programming and Scripting

Format CSV file

I have a csv file which I need to process and export back to xlsx file. For instance, the csv contains: John Smith, job-title, hours John Smith, job-title, hours Mary Smith job-title, hours etc. I need to import that to a script, get id of redundant data i.e: John smith, job-title,... (13 Replies)
Discussion started by: _tina_
13 Replies

9. UNIX for Dummies Questions & Answers

Unix script to convert .csv file to.xls format

I have a .csv file in Unix box i need a UNIX script to convert the.csv files to.xls format. Its very urgent please help me. (1 Reply)
Discussion started by: moon_friend
1 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question