How to retrive data from DB(Aqua studio) in CVS format using UNIX script?

I am using aqua studio DB. I need to retrive the data from my database using uxin script in .csv format. i am using select query along with the joins. my o/p in the DB is of the below format.

Cycle IDCycle StatusRecord 98N-0000ACV23-3636FCliet Level (Af)Success1689393HF-J7879-09090RCliet Level (Af)Success2356765KD-7HWE747-9I9KPst Leve (Bf)failure45

This is about 120 rows. i need the o/p in .csv format using shell script. I am using bash shell. Couls some one help me on this

The first queston in csv solutions is "Does the data include char with comma or double quotes?"

  • If not, it never needs quoting or escapes.
  • In csv, embedded commas must be double-quoted and embedded double quotes must be doubled! For example, if a column contained ' We said "Hello, sailor!" ', then it needs to be ' "We said ""Hello, sailor!"" ' or even ' We said ""Hello"," sailor!"" ' (double quotes right around the comma)! Many double quote every column against commas, but most forget double quote doubling! In a C/C++/JAVA/PERL program, you can detect comma and only quote on need, whole column in case it has multiple commas, for a minimum file size. CSV is very compressible, too.

You can select into excel with odbc and save as csv!

You can select with any command line tool (isql from unixODBC, jisql for xigole w/JDBC) and use sed or awk to reformat it trimmed with comma separators.

If the tool has a column separator, you can set it to comma, or convert it to comma.

You can put the commas in your select: select col_a || ',' || col_b .... Sometimes the concatenated string exceeds the allowed length unless you break it up.

You can put a marker on the data lines so they are simple to detect and separate from headings, error reports and status:

echo "
 select 'dAtAq,' || col_a || ',' || col_b || ....
" | isql ... | sed -n '
  s/^dAtAq,//p
  t
  w logfile
 ' > xxx.csv

We could process in bash if you insist.