UNIX - how to send attach excel in mail

Hi Experts,
i need your help here
:confused:

Need to send a report thru mail using unix shell script(AIX). can you help me to do this? . i tried "uuencode" with CSV format, but while reading report all values are in single column. i need each column values in separate cell.

Thanks in advance...

Welcome newbieabc,

Are you saying that the file was attached to the email okay? If so, then we need to check the format of your file.

Excel can read most things quite well, but I think your file is space separated. If you use a comma to separate the columns and then see what Excel makes of it, that might help. The CSV does stand for Comma Separated Values after all.

If this still doesn't help, change it to be a .txt file and then Excel will launch the import wizard and guide you through opening it where you can tell it the column separators/delimiters or fixed column widths or whatever.

I hope that this helps. Let us know how you get on.

Robin

It's also possible that you forgot to add carriage returns to your file before you sent it. Windows/Excel expects these, it will not see \n by itself as an indicator of a new line. To add them to a file:

sed 's/$/\r/' < input.csv > output.csv
2 Likes

Hi Robin,
Thank you very much for replying,
yes, i am able to send the file via mail (attachment). While opening the file in excel (whatever the format .CSV or .xls) the outputs are in single column.

eg:

A1 B1 C1 D1 E1...
hello welcome to unix forum

But i want like this.

A1... B1....... C1 D1.. E1....
hello welcome to unix forum

this should me done in shell script. i dont want to do anything in excel.

Please help me.

thanks,

---------- Post updated at 03:12 AM ---------- Previous update was at 03:07 AM ----------

Hi Corona688,

Thanks for your suggestion. I tried it, it didn't work. Can you please help?

Thanks,

Post a sample of your csv file.

Also, "it didn't work" is not a useful description to anyone trying to help. Did it generate an error, produce the wrong (or no) output? What?

Hi CarloM,
Sorry for the inconvenience,
It doesn't produce any error. but outputs are in single column, doesn't intended in Excel.

Here is my sample code:

ls -ltr /home/$USER >~/log.csv
sed 's/$/\r/' <~/log.csv >~/log1.csv
uuencode log1.csv log.csv >report
mail -s "Report" #email_id# <report

Thanks,

ls -ltr /home/$USER

That's not going to have any commas in it - hence, only 1 column.

Do you want all the data from ls, or just the filenames?

1 Like

Actually i am getting data from DB and exporting to CSV file. i just gave "ls -ltr" for example.
My log.csv file will be like.

3,1463,1032855,20140627,"xxxxxxx","yyyyyyy"
3,1260,1032504,20140626,"aaaaaaa","bbbbbbbb"

When the file is sent, is it still named as a .csv? You could also try calling it a .txt which should get Excel to fire up the import wizard where you can manage the delimiters yourself.

As a test, if you create the following file with Notepad on your PC saving it as both my_test.csv and my_test.txt, can Excel open them? If so what does it do with the files?

1,2,3,4,5
a,b,c,d,e
A,B,C,D,E

Don't use anything fancy as the editor. A plain notepad is best so it does not add in all the editor specific detail such as MS-Word, StarOffice, etc. will.

As a further test, can you create a simple spreadsheet and save it as a CSV. Then, use notepad to have a look at what it's written.

I hope that this helps,
Robin

1 Like

Thanks a lot, it worked...