Writing in excel sheet using ksh

Hello,

I'm trying to write a script to export a txt file to excel. The text file is a delimited with commas

Example:

Report Date,12/12/2014
Report By, Person
Issue, Job Failed

I tried exporting as csv and mailed to my id. But if I open the csv file the data is coming in single column.

Output I'm getting:

Column A
Report Date,12/12/2014
Report By, Person
Issue, Job Failed

But I'm expecting below output

Column A      Column B
Report Date   12/12/2014
Report By      Person
Issue            Job Failed

I checked the forum. I'm getting examples to export txt to csv which gives the similar result as what I'm getting. I dont have perl so I need a solution to get the above output using ksh

Could someone please help.

I believe excel defaults to tab rather than comma separation, so a simple sed 's/,/\t/g' <file.txt> should work, no?

1 Like

Naming the file to with .csv extension works for me. First, its automatically associated with excel and fields are correctly parsed.

1 Like

If you save it with a .txt suffix and then open it with Excel, it will start the wizard where you can define the columns and how you import it. Mark it as delimited and check the comma selection.

Robin

1 Like

Tabs actually work much, much better since they don't appear in data as often as commas do.

Make sure your lines end in \r\n if you're importing into Excel.

1 Like

Thanks everyone. Tab space is working fine....

I have written a number of shell scripts that generated .csv files and emailed them out. Generally I use the double quote comma delimiter. As in:

"col1","col2","col3","col4"...

That might work as well, since you still might get a tab in your data.