Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

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

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 09-17-2009
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 max(sequence#) from v\\\$log_history;
exit;
END`

$VALUE=$VALUE + 1

---------------------------------

Problem is, as soon as i use the variable returned from the sqlplus call, it gives me the following error:

bash: $'184\r=': command not found

I have gone through any number of code syntax and i still need help getting this \r guy out of the variable into a new one so i can do some operations on it.

Any help is "GREATLY" appreciated

---------- Post updated at 04:51 AM ---------- Previous update was at 04:35 AM ----------

I am guessing this problem will not be resolved if i spool the output to a file and read it back in?

Any help is appreciated.

Thanks,
# 2  
Old 09-17-2009
this will not work:
Code:
$VALUE=$VALUE + 1

assuming, that "\r" are two printable characters \ and r:

Code:
VALUE='5\r'
VALUE=$(($(echo $VALUE | sed 's/\\r//') +1))
echo $VALUE
6

should work for ksh and bash

cheers
# 3  
Old 09-17-2009
first of all
you specify KSH but the error states you're working in bash

this wotks for me
Code:
@ecarh0u:> value=""
@ecarh0u:> value=`sqlplus -s $user/$pwd@osdp << EOF
more>set pages 0 feed off hea off;
more>select max(sequence#) from v\\\$log_history;
more>exit;
more>EOF
more>`
@ecarh0u:> echo $value
42765
@ecarh0u:> ((value=$value + 1))
@ecarh0u:> echo $value         
42766

Is there a dollar sign before your first occurence of value ($VALUE=$VALUE + 1) or is this your prompt ? If it is a dollar, remove that one.
# 4  
Old 09-17-2009
Thanks, will look into this and post my feedback. Regards and thank you very much for helping out. You guys are great.

Best regards,
# 5  
Old 09-17-2009
Code:
 
#!/bin/ksh
VALUE=`sqlplus -silent "/ as sysdba" <<END
set pagesize 0 feedback off verify off heading off echo off
select max(sequence#) from v\\\$log_history;
exit;
END`
 
VALUE=$VALUE + 1

Replace
$VALUE=$VALUE + 1
with
VALUE=$VALUE + 1
to increment archive log number.

Urs
# 6  
Old 09-18-2009
Quote:
Originally Posted by scripter.online
Code:
 
#!/bin/ksh
VALUE=`sqlplus -silent "/ as sysdba" <<END
set pagesize 0 feedback off verify off heading off echo off
select max(sequence#) from v\\\$log_history;
exit;
END`
 
VALUE=$VALUE + 1

Replace
$VALUE=$VALUE + 1
with
VALUE=$VALUE + 1
to increment archive log number.

Urs
are you sure? I don't think so...
# 7  
Old 09-18-2009
funksen is right . Both cases are syntax errors and do not do arithmetic.

Also, are you sure about

Quote:
v\\\$log_history
Assuming that the table is called v$log_history , we only need one backslash to protect the $ from shell.

Quote:
v\$log_history
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove carriage return and append the next line mad man Shell Programming and Scripting 16 05-12-2016 08:46 AM
Remove Carriage Return (CRLF) within double quotes covina Shell Programming and Scripting 12 07-27-2015 01:51 PM
Remove carriage return srvn_saru UNIX for Dummies Questions & Answers 11 04-03-2014 12:56 AM
Remove carriage return from the variable Meacham12 Shell Programming and Scripting 6 12-06-2013 06:03 AM
Awk to remove carriage return from 65th field pinnacle Shell Programming and Scripting 7 03-22-2012 11:51 AM
Remove carriage return in a record agathaeleanor Shell Programming and Scripting 10 08-03-2011 04:29 AM
Remove ^M (carriage return) with string manipulation aquila_1 UNIX for Dummies Questions & Answers 3 05-28-2011 04:24 PM
sqlplus returns leading carriage return into a variable Panzer993 Shell Programming and Scripting 7 04-14-2011 10:50 AM
To remove carriage return between the line shash UNIX for Dummies Questions & Answers 5 07-31-2007 12:12 PM
Remove a carriage return at end of variable flagship99 UNIX for Dummies Questions & Answers 5 11-17-2004 05:39 PM


All times are GMT -4. The time now is 09:16 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password