SQL Query in Shell Script output formatting

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SQL Query in Shell Script output formatting
# 1  
Old 11-27-2013
SQL Query in Shell Script output formatting

Hi All,
call_sql ()
sqlplus -s $sqlparam_sieb <<EOF
                     SET ECHO OFF;
                     SET NEWPAGE NONE;
                     SET SQLBL OFF;
                     SET VERIFY OFF;
                     SET LINESIZE 2000;
                     SET PAGESIZE 500;
                     SET TRIMS ON;
                     SET HEADING OFF;
                     SET FEEDBACK OFF;
                     SET WRAP OFF;
reslt=$(call_sql "select NVL(error_message,'No Error'), count(1) from siebstg.stg_aa_member_profile_int group by error_message order by count(1) desc")
echo with quotes
echo "$reslt"

echo without quotes
echo $reslt

And below is the output what i get ...

with quotes
No Error                                                                                                                                                                   240
*PSC*                                                                                                                                                                       11
*NNF*                                                                                                                                                                       10
*MEM*                                                                                                                                                                        8
*FNM*                                                                                                                                                                        1
*DTE*                                                                                                                                                                        1
without quotes
No Error 240 *PSC* 11 *NNF* 10 *MEM* 8 *FNM* 1 *DTE* 1

I need the output it in below format..
No Error 240
*PSC*    11 
*NNF*    10 
*MEM*    8 
*FNM*    1 
*DTE*    1

# 2  
Old 11-27-2013
Try echo "$reslt" | dos2unix
# 3  
Old 11-27-2013
No, Luck.... Still the same
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Not able to write SQL query output in to .csv file with shell script.

I am trying to write SQL query output into a .csv file. But in the output columns are displaying in different lines instead of coming in one line. Main Code shell script: this is my code: #!/bin/bash file="db_detail.txt" . $file rm /batch/corpplan/bin/dan.csv... (6 Replies)
Discussion started by: sandeepgoli53
6 Replies

2. Shell Programming and Scripting

Shell script appending output of sql query

I am writing the following script to create the file v_out.txt. sqlplus -s /nolog << EOF CONNECT scott/tiger@orcl; whenever sqlerror exit sql.sqlcode; set newpage 0; SET PAGESIZE 0; SET ECHO OFF; SET FEEDBACK OFF; SET HEADING OFF; SET VERIFY OFF; SET LINESIZE 100; set tab off; set... (7 Replies)
Discussion started by: itzkashi
7 Replies

3. Shell Programming and Scripting

Run sql query in shell script and output data save as delimited text

I want to run sql query in shell script and output data save as delimited text (delimited text would be comma) Code: SPOOL_FILE=/pgedw/dan.txt SQL=/pgedw/dan.sql sqlplus -s username/password@myhost:port/servicename <<EOF set head on set COLSEP , set linesize 32767 SET TRIMSPOOL ON SET... (8 Replies)
Discussion started by: Jaganjag
8 Replies

4. Shell Programming and Scripting

SQL query in UNIX script - output in flat file

Hi, I never did this before... what I want to do is execute a SQL query from a unix script and redirect sql query's output to a flat file (comma separated one) without the header info (no column names). I would also want not to print the query's output to the screen. snapshot of my script:... (13 Replies)
Discussion started by: juzz4fun
13 Replies

5. Red Hat

Sql query through shell script

hey , i am using this code to store value of a sql query and and then use it in other query but after some time , but it is not working. please help #!/bin/bash val_1=$( sqlplus -s rte/rted2@rel76d2 << EOF setting heading off select max(stat_id) from cvt_stats; exit EOF ) nohup... (5 Replies)
Discussion started by: ramsavi
5 Replies

6. Shell Programming and Scripting

Problem in formatting output of SQL query in excel sheet in shell script

Hi Guys.. Need your help to format the output of my shell script. I am using spool command to take out put in csv file. below is my code. (for example) col USERNAME for a15 col EMAIL for a30 col FULL_NAME for a20 col LAST_LOGIN for a40 col DATE_CREATED for a40 SPOOL 120.csv... (3 Replies)
Discussion started by: Agupte
3 Replies

7. Shell Programming and Scripting

sql select command output formatting in shell script

Hi, I need to connect to the database and retrieve two variables from the database and store them in a variable,out of these two variables I need to get lastdigit appended to the variable 1 retrieved and variable 2 with out any modification in short select var,data from usage; o/p=... (1 Reply)
Discussion started by: rkrish
1 Replies

8. Shell Programming and Scripting

Formatting the query output using shell script

Hi All, I'm finding it difficult to format the query output that was returned in a shell script. Actually i have one shell script which does some DB stuff and depending on the result it will do some more tasks. My question here is to format the query output returned by mysql. Intitally my... (5 Replies)
Discussion started by: RSC1985
5 Replies

9. Shell Programming and Scripting

query sql using shell script

query sql using shell script, is it possible? my friend told me to do a file.sql and link to my shell script, but can i query sql using shell script? thanks in advance! (2 Replies)
Discussion started by: kingpeejay
2 Replies

10. Shell Programming and Scripting

need help in reading a output of a sql query in unix script

i'm used a sql query in a unix script to get the information from table. but unable to extract the output which i need. Any help with logic will be greatly appreciated. my sql query provide output some thing like this - col1 col2 count ---- ---- ------ A B 10 c D 6 e... (8 Replies)
Discussion started by: pharos467
8 Replies
Login or Register to Ask a Question

Featured Tech Videos