LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-30-2010, 02:20 PM   #1
vjy
Member
 
Registered: Oct 2004
Posts: 31

Rep: Reputation: 0
sed & script help


I am trying to write a script to access sqlplus and use the output to replace the result in another file. But I am having some issues with it (This script is just a test script and I am just trying to print the updated value.

#!/bin/bash

a=`echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql`
bb=$a
echo a is $a
echo bb is $bb

var=he-llo

echo "goodbye friend" | sed "s/goodbye/$var/"

echo "goodbye friend" | sed "s/goodbye/$bb/"


The output I get is

a is 30-APR-10
bb is 30-APR-10
he-llo friend
sed: -e expression #1, char 10: unterminated `s' command

I am not sure why the last statement alone is not executing. Am I missing something?

Thanks.
 
Old 08-30-2010, 02:37 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I don't think you are missing anything. If I try the example you posted it does work.

Your programming style could be better and could cause problems later on, but that's not the problem in this case. (you need to quote; var='he-llo', bb="$a". single or double, depends on what you want/need. use double for the time being).

Recheck you original script, maybe there is a typo or something else that doesn't belong.

Hope this helps.
 
Old 08-30-2010, 02:57 PM   #3
vjy
Member
 
Registered: Oct 2004
Posts: 31

Original Poster
Rep: Reputation: 0
Thanks druuna for the reply. The script is ugly because its test, once I make it work, I will copy the one to the original script.

Anyways I have tried bb="$a" before, but still I got the same error.

I defined var="he-llo" initially. Just to check I removed the quotes.

Anyways I am running this script only and I still get that error.

The sql file I execute is
set echo off
set feedback off
set verify off
set heading off

select max(date) from tablename;

Thanks again.
 
Old 08-30-2010, 03:13 PM   #4
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
A newline in $a could cause the error message.
Demonstration:-
Code:
a='
30-APR-10'   #  Set $a containing a newline
bb=$a
echo a is $a
echo bb is $bb

var=he-llo

echo "goodbye friend" | sed "s/goodbye/$var/"

echo "goodbye friend" | sed "s/goodbye/$bb/"

# Gives the same output as your script:-
a is 30-APR-10
bb is 30-APR-10
he-llo friend
sed: -e expression #1, char 10: unterminated `s' command
To remove all newlines in $a try either
bb=${a//$'\n'/}
or
bb=${a//
/}
 
1 members found this post helpful.
Old 08-30-2010, 03:15 PM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by vjy View Post
Thanks druuna for the reply. The script is ugly because its test, once I make it work, I will copy the one to the original script.

Anyways I have tried bb="$a" before, but still I got the same error.

I defined var="he-llo" initially. Just to check I removed the quotes.
Yes, just like I stated in my previous reply. The problem lies elsewhere.

Quote:
Anyways I am running this script only and I still get that error.
Are you still talking about the quoting or is this about the sql file? I assume it is about the quoting, an sqlplus statement cannot produce a sed error.....

One thing I don't get:
In your first post you showed a script and its output. This part a=`echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql` does fill a (a is 30-APR-10).

Does echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql work from the command line (although post #1 does suggest it works)??
 
Old 08-30-2010, 05:39 PM   #6
vjy
Member
 
Registered: Oct 2004
Posts: 31

Original Poster
Rep: Reputation: 0
Thanks Kenhelm,

its just the newlines and your suggestion worked fine.

druuna,

echo exit|sqlplus -S -L xxx/xxx@xxx @test.sql executed fine, its just that the newlines messed it up. After I did what Kenhelm suggested, it worked. I should have thought of that before.

Thanks to both for the help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to remove script data from file using grep & sed djlane Programming 1 07-13-2010 08:10 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
sed & grep script? dolvmin Linux - Software 20 09-22-2003 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration