sqlplus returns leading carriage return into a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sqlplus returns leading carriage return into a variable
# 1  
Old 04-13-2011
sqlplus returns leading carriage return into a variable

I am trying to generate some scripts to help manage an Oracle database. When I check the value returned from Oracle it has a leading carriage return in the variable. Is there a way to prevent this? Is there a way to easily strip out the carriage return. See code and output below.
Code:
LASTFILE=$(sqlplus -s "/ as sysdba" <<EOF
       set head off
        select file_name from dba_data_files
        where tablespace_name = upper('$TABLESPACE') and
        file_id in (select max(file_id) from dba_data_files 
        where tablespace_name = upper('$TABLESPACE'));
        exit
EOF)

echo "Last data file = $LASTFILE"

Output looks like this:
Code:
Last data file = 
/u01/oradata/database/file_name

The file name gets wrapped after the =

Any help will be greatly appreciated.

Last edited by Scott; 04-13-2011 at 07:22 PM.. Reason: Please use code tags
# 2  
Old 04-13-2011
try
Code:
...
set head off
set linesize 150
...

# 3  
Old 04-13-2011
I found this and it works.
Code:
LASTFILE=`echo $LASTFILE`

echo "Last file = $LASTFILE"

Output looks like this:
Code:
Last file = /u01/oradata/database/file_name

If anyone has a better way please let me know but this works.

Last edited by Franklin52; 04-14-2011 at 03:17 AM.. Reason: Please use code tags, thank you
# 4  
Old 04-13-2011
give a try separating EOF and put the ending parenthesis on a new line
you could also give a try using back quote instead of the $( ) notation
# 5  
Old 04-13-2011
It had the same issue with the back quotes (ticks). That is why I was trying the ().

Putting the back quote on the line after the EOF does not work either.

Using the echo command works and I guess I'll stay with that for now.

Thanks!!!!!
# 6  
Old 04-13-2011
set newpage 0
set pagesize 0

?

---------- Post updated at 12:34 AM ---------- Previous update was at 12:18 AM ----------

you may also try to add the hyphen
<<-EOF
instead of
<<EOF
# 7  
Old 04-13-2011
That works!! Much cleaner and less code.

Thank you!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove carriage returns from awk output

I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell. I'm working with the input file: John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams,... (2 Replies)
Discussion started by: prooney
2 Replies

2. UNIX for Beginners Questions & Answers

Carriage return with cat variable

Hi, I wish to know how to works the carriage return with cat.. As a picture often speaks better than words, my code below : #te=`cat text.txt` (I tried this, but the same..) te=$(cat text.txt) echo $te My file text.txt below: BLABLABLABLABLALBLA BLABLABLABLABLALBLA ... (9 Replies)
Discussion started by: Arnaudh78
9 Replies

3. Shell Programming and Scripting

Remove carriage return from the variable

Hi, I try to handle very large numbers with a bash script. I run ssh command in a remote server and store the output in a local variable. But this output contains a return carriage at the end. So I try to remove it by tr But I can't figure out the right notation with printf. So my problem... (6 Replies)
Discussion started by: Meacham12
6 Replies

4. Shell Programming and Scripting

TR not removing carriage returns

I have a CSV with carriage returns in place of newlines. I am trying to use tr to remove them, but it isn't working. Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,4th Period,Arnold,Adam 2012-2013,First Semester,English 12,4th Period,Adams,Jim... (1 Reply)
Discussion started by: nextyoyoma
1 Replies

5. Shell Programming and Scripting

A variable is including the Carriage Return char...

Hi all, I'm reading a file with this layout: First_Col Second_Col The Second_Col has values as 1000, -1, 10, 43... While reading the file I'm getting the second column value with awk command, but it is including the CR control char. do item_saved=`echo $b | awk '{print... (4 Replies)
Discussion started by: mrreds
4 Replies

6. Shell Programming and Scripting

sqlplus returning value - remove carriage return '\r' - Please help

Guys - Simple code, i am trying to get a number back from sqlplus call to a query. After that, i need to use that number in a loop. --------------------------------- #!/bin/ksh VALUE=`sqlplus -silent sh/password@sh <<END set pagesize 0 feedback off verify off heading off echo off select... (10 Replies)
Discussion started by: sunshine1974
10 Replies

7. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

8. Shell Programming and Scripting

Removing carriage returns with sed

How do we delete all carriage returns after a particular string using sed inside a K Shell? e.g. I have a text file named file1 below: $ more file1 Group#=1 User=A Role=a1 Group#=2 User=B Role=a1 Role=b1 Group#=3 User=C Role=b1 I want the carriage returns to be delete on the... (12 Replies)
Discussion started by: stevefox
12 Replies

9. Shell Programming and Scripting

spaces and carriage returns in 'here documents'

As the title suggests, i am having some trouble figuring out how to pass spaces and carriage returns to a 'here document' ie #!/bin/bash /usr/local/install_script.sh <<SCRIPT yes no <pass carriage retun here> yes no <pass a space and then a carriage return here> exit SCRIPT any... (0 Replies)
Discussion started by: hcclnoodles
0 Replies

10. UNIX for Dummies Questions & Answers

Remove a carriage return at end of variable

Is there a command in unix to remove a carriage return character(^M) at the end of a variable value? (5 Replies)
Discussion started by: flagship99
5 Replies
Login or Register to Ask a Question