Shell Script for converting file to Excel or CSV

Hi I have a dat file which has "n" number of columns. The file is delimited. The number of columns keep varying as the file is generated out of DB queries. Could you please help me in writing a script which will generate a XLS or CSV file out of the dat file.

Turning your DAT into a CSV simply means changing your delimiters from whatever they are now, into commas. CSV = "comma separated values".

If your data contains commas, you may need to quote the sections.

What is your delimiter?

If your data is spooled from DB, you can create a CSV output by setting the column separator to comma in SQL:

set colsep ,

Corona- the delimiter would be \t.

The query is being run in a tool(ETL_Abinitio).

awk -F'\t' '{$1=$1}1' OFS=, file

If your data doesn't contain commas:

tr ',' '\t' < inputfile | sed 's/$/\r/' > outputfile