Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-17-2009   -   Original Discussion by sunshine1974
sunshine1974's Unix or Linux Image
sunshine1974 sunshine1974 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 21 September 2009, 2:43 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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,
Sponsored Links
    #2  
Old Unix and Linux 09-17-2009   -   Original Discussion by sunshine1974
funksen's Unix or Linux Image
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 7 June 2017, 11:09 AM EDT
Location: Austria/Vienna
Posts: 682
Thanks: 25
Thanked 31 Times in 30 Posts
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
Sponsored Links
    #3  
Old Unix and Linux 09-17-2009   -   Original Discussion by sunshine1974
plelie2's Unix or Linux Image
plelie2 plelie2 is offline
Registered User
 
Join Date: Jul 2002
Last Activity: 7 November 2013, 4:04 AM EST
Location: Belgium
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
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 Unix and Linux 09-17-2009   -   Original Discussion by sunshine1974
sunshine1974's Unix or Linux Image
sunshine1974 sunshine1974 is offline
Registered User
 
Join Date: Sep 2009
Last Activity: 21 September 2009, 2:43 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks, will look into this and post my feedback. Regards and thank you very much for helping out. You guys are great.

Best regards,
Sponsored Links
    #5  
Old Unix and Linux 09-17-2009   -   Original Discussion by sunshine1974
scripter.online's Unix or Linux Image
scripter.online scripter.online is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 15 January 2017, 3:55 AM EST
Location: India
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts

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
Sponsored Links
    #6  
Old Unix and Linux 09-18-2009   -   Original Discussion by sunshine1974
funksen's Unix or Linux Image
funksen funksen is offline Forum Advisor  
Registered User
 
Join Date: Nov 2006
Last Activity: 7 June 2017, 11:09 AM EDT
Location: Austria/Vienna
Posts: 682
Thanks: 25
Thanked 31 Times in 30 Posts
Quote:
Originally Posted by scripter.online View Post

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...
Sponsored Links
    #7  
Old Unix and Linux 09-18-2009   -   Original Discussion by sunshine1974
methyl's Unix or Linux Image
methyl methyl is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
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
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
add carriage return at end of file HAA Shell Programming and Scripting 2 11-20-2007 11:58 AM
To remove carriage return between the line shash UNIX for Dummies Questions & Answers 5 07-31-2007 01:12 PM
returning value from sqlplus malaymaru Shell Programming and Scripting 1 01-31-2006 04:03 AM
Remove a carriage return at end of variable flagship99 UNIX for Dummies Questions & Answers 5 11-17-2004 06:39 PM
Print not carriage returning bbpd.helpdesk UNIX for Dummies Questions & Answers 3 11-20-2000 07:59 AM



All times are GMT -4. The time now is 12:49 PM.