LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-10-2016, 04:07 AM   #1
vnarvankar
LQ Newbie
 
Registered: Mar 2016
Posts: 1

Rep: Reputation: Disabled
SED command failing while substituting variable with error unterminated `s' command


I am trying to run sed from script to replace a value in a string with a variable.
cat FileLoad.template | sed -e "s#<<SID>>#$v_sid#g" > FileLoad.ctl

This FileLoad.template contains the string <<SID>> and it should be replaced with value in v_sid. Value in v_sid is A145_20120348. While substituting with this value it failing with error unterminated `s' command. Can anyone suggest what is wrong in this command?
 
Old 03-10-2016, 07:09 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,267
Blog Entries: 13

Rep: Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353Reputation: 4353
While written in a vastly different manner from how I'd do this, the sed command you've written should work. I'm guessing this depends upon the environment from which you're running. I have BASH for my shell.

A suggestion to try:
Code:
/bin/sed -e s/<<SID>>/$v_sid/g FileLoad.template > FileLoad.ctl
Another suggestion to try:
Code:
/bin/sed -e s/\<\<SID\>\>/$v_sid/g FileLoad.template > FileLoad.ctl
 
Old 03-10-2016, 09:10 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,535

Rep: Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077
Quote:
Originally Posted by vnarvankar View Post
I am trying to run sed from script to replace a value in a string with a variable.
cat FileLoad.template | sed -e "s#<<SID>>#$v_sid#g" > FileLoad.ctl
Works fine for me. Try using "set -x" so that you can see what arguments the shell is actually passing to the sed command.

BTW, this is one of those "useless use of cat" occasions. The sed command is perfectly able to read that file itself.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use variable value in sed command PravinNagare Linux - Newbie 6 02-05-2014 07:08 AM
how to use variable in sed command ? anandg111 Linux - Newbie 3 01-11-2012 11:27 AM
Problem using sed with variable created using xargs - unterminated error wrankin Programming 5 11-14-2011 07:53 PM
[SOLVED] sed unterminated `s' command random0munky Linux - Newbie 7 08-19-2011 11:43 AM
sed: Unterminated 's' command whatis Programming 2 11-02-2009 02:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:33 AM.

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