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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to retrive data from DB(Aqua studio) in CVS format using UNIX script?
# 1  
Old 03-13-2013
Linux 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
# 2  
Old 03-13-2013
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:
Code:
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.

Last edited by DGPickett; 03-13-2013 at 05:31 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

2. Shell Programming and Scripting

Perl -- Script to re-format data

Hi, I have a file with data in the following format BOX -1.000000 -1.000000 0.000000 30.00000 14.00000 0.1000000 0.000000 0.000000 0.000000 0.000000 0.000000 CYLINDER 3.595000 2.995000 0.000000 0.5100000 2.000000 Z 0.000000 0.000000 0.000000 I want to convert these files... (1 Reply)
Discussion started by: lost.identity
1 Replies

3. Programming

updating data in cvs file using c programming

hi every one i want to read and write data from cvs file using c program. but my problem is that at run time my data is increasing in both row wise and column wise. that means it is continuously updating in both direction. is there any way through which i can find the next colum or row for eg... (0 Replies)
Discussion started by: sajidtariq
0 Replies

4. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

5. Shell Programming and Scripting

Need script to format data specifically

Hi all, I need a script specially using loops to print below output... variables x, a and b will be read from user... x a b x+1 a b+1 x+2 a b+2 x+3 a+1 b x+4 a+1 b+1 x+5 a+1 b+2 for example.... 1 ... (4 Replies)
Discussion started by: swapniltathe
4 Replies

6. UNIX for Advanced & Expert Users

shell script to format .CSV data

Hi all, I have written a shell script to search a specified directory (e.g. /home/user) for a list of specific words (shown as ${TMPDIR}/wordlist below). The script works well enough, but I was wondering if there was a way to display the line number that the word is found on? Thanks! cat... (1 Reply)
Discussion started by: tmcmurtr
1 Replies

7. Shell Programming and Scripting

Shell script to format a .CSV data

Hi There I needed to write a Unix shell script which will pick up the data from a .CSV file and reformat it as per the requirement and write it to another .CSV file. Currently I am in the proess of Data Import to "Remedy System" (A one kind of incident mangement Application) and this... (8 Replies)
Discussion started by: Uday1982
8 Replies

8. Shell Programming and Scripting

to retrive data that appear only once in a file.

hi, I need to get the list of functions that are used more than once in a file list. Thanks in advance (1 Reply)
Discussion started by: anibu
1 Replies

9. Shell Programming and Scripting

help to retrive data from log file

hi i have following file. where i m trying to retrive data on latest date. let us say we are extracting data from this file for Jun 30 where date is highest date in log file. here i want to take output in other file from first line of Jun 30 to the end of file in short i want retrive... (5 Replies)
Discussion started by: d_swapneel14
5 Replies
Login or Register to Ask a Question