Output from sql session having an extra whitespace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output from sql session having an extra whitespace
# 1  
Old 10-06-2010
Question Output from sql session having an extra whitespace

I am running a sql session within a shell script. Later I am performing some validations on the value coming from the sql session.
The problem is that, the value I am getting from sql session have an extra white space at the begining(I am actually, assigning the outcome of the sql session to a variable).
I have tried with sed 's/^ *//', but was unable to delete that white space.
Please let me know why this is happening and the remedy to it.
# 2  
Old 10-06-2010
one way:

Code:
sed 's/^ //'

second way:

change the select statement of sql to :

Code:
select '~'||column1||'~'

in the shell script :

Code:
 
sed 's/~//g'

# 3  
Old 10-06-2010
Error Its not working

Here is the script :
Code:
cntrct_desc=`sqlplus -s  <<eof
whenever sqlerror exit 1
set feedback off;
set verify off;
set echo off;
set heading off;
select '~'||b.cpgrp_desc||'~' from cont a,cpgrp b
where cpgrp_cont_id_alias='756274934'
and a.cont_num=b.cont_num;
eof`
echo $cntrct_desc
leng=${#cntrct_desc}
echo $leng
cntrct_desc=$(echo "$cntrct_desc"  | sed 's/~//g')
echo "contarct description : "123${cntrct_desc}123

The Outcome should be "Linc Children's Hospital".....but its coming as " Linc Children's Hospital"

Last edited by Scott; 10-07-2010 at 08:22 PM.. Reason: Code tags
# 4  
Old 10-06-2010
strange, but the same work's with me.

Code:
 
$ echo " Linc Children's Hospital" | sed 's/^ //'
Linc Children's Hospital

# 5  
Old 10-06-2010
MySQL thanks, the problem was else where...

The problem was in the portion I marked in red :
Code:
cntrct_desc=`sqlplus -s  <<eof
whenever sqlerror exit 1
set feedback off;
set verify off;
set echo off;
set heading off;
select '~'||b.cpgrp_desc||'~' from cont a,cpgrp b
where cpgrp_cont_id_alias='756274934'
and a.cont_num=b.cont_num;
eof`
echo $cntrct_desc
leng=${#cntrct_desc}
echo $leng
cntrct_desc=$(echo "$cntrct_desc"  | sed 's/~//g')
echo "contarct description : "123${cntrct_desc}123

That should be....
Code:
cntrct_desc=$(echo $cntrct_desc  | sed 's/~//g')

Actually double quotes were creating the error.
Thanks a lot again.

Last edited by Scott; 10-07-2010 at 08:22 PM..
# 6  
Old 10-06-2010
Quote:
Originally Posted by mady135
The problem was in the portion I marked in red :
cntrct_desc=`sqlplus -s <<eof
whenever sqlerror exit 1
set feedback off;
set verify off;
set echo off;
set heading off;
select '~'||b.cpgrp_desc||'~' from cont a,cpgrp b
where cpgrp_cont_id_alias='756274934'
and a.cont_num=b.cont_num;
eof`
echo $cntrct_desc
leng=${#cntrct_desc}
echo $leng
cntrct_desc=$(echo "$cntrct_desc" | sed 's/~//g')
echo "contarct description : "123${cntrct_desc}123

That should be....
cntrct_desc=$(echo $cntrct_desc | sed 's/~//g')

Actually double quotes were creating the error.
...

Strange... why not just fetch the trimmed value of column "cpgrp_desc" instead of adding those characters and then removing them with sed and all that jazz ??

Code:
select TRIM(b.cpgrp_desc) from cont a,cpgrp b
where cpgrp_cont_id_alias='756274934'
and a.cont_num=b.cont_num;

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script when scheduled in Crontab gives extra records in output

Hi, We have created a script that's checks the latency of IIDR subscription by fetching details from a config file (that contains subscription details) and running the CHCCLP command. The out put is then concatenated in a csv file. Once all subscription details are saved the script send a mail... (7 Replies)
Discussion started by: ab095
7 Replies

2. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

3. Shell Programming and Scripting

Extra data in output file

Gents, I did a small scritp called make_file It read file1.txt file and generate an output as attached.. But the script is showing more extra information not needed. I have attached the output file as desired. Could you please help to fix this scrip to get the correct output Thanks... (4 Replies)
Discussion started by: jiam912
4 Replies

4. Shell Programming and Scripting

Extra Space in output - remove

Hi All I am trying to perform the below operation -count=`cat abc.txt | wc -l` echo$count 5 Head=Start"$DATE"00000"$count"File echo $HEAD START15020300000 5File There is a space coming before 5 which is not needed . How to ignore that . (4 Replies)
Discussion started by: honey26
4 Replies

5. Shell Programming and Scripting

Need Help: Shell script to call sql session with variables stored in .txt file

Hi, I need help in writing a shell script which can read data from a text file (Cancel_ID.txt) and then calls sqlplus session (Cancel.sql) with the first line parameter of the text file ("0322600453") till all rows are not completed. ... (4 Replies)
Discussion started by: Khan28
4 Replies

6. Shell Programming and Scripting

formatting into CSV format of SQL session output

I am getting a no of fields from a SQL session (e.g. select a,b,c from table). How do I convert the output values into CSV format . The output should be like this 'a','b','c', (4 Replies)
Discussion started by: mady135
4 Replies

7. Shell Programming and Scripting

How to pass value from unix shell to sql session?

Here is the situation, I have file from which I am reading records line by line. Based upon some condition I need to pass a field from a sql session to get some data from a table. I don't have any idea how to do it.... (1 Reply)
Discussion started by: mady135
1 Replies

8. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

9. Filesystems, Disks and Memory

vxdisk list output showing extra LUNs

hi fren i am facing this problem i have sun 6140 storage 30 volumes bt my vxdisk list output is showing 37 disk which shd nt b there has neone faced this proble earlier vxdiks list output is like this SUN6140-2_0 auto - - online c4t201700A0B84853C0d2s2 SUN6140-2_1 auto - - online... (13 Replies)
Discussion started by: bond_ankur
13 Replies

10. Shell Programming and Scripting

Extra output in the script

Hi , I am trying to execute the following script. #!/bin/sh find . -name "common.log.diff" if ; then cp common.log common.log.diff diff common.log common.log.diff > DIFFERENCE.log cp common.log common.log.diff grep "ERROR" DIFFERENCE.log if ; then echo "1" else echo "0" fi... (5 Replies)
Discussion started by: himvat
5 Replies
Login or Register to Ask a Question