LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-16-2008, 07:21 PM   #1
morphixrocks
Member
 
Registered: Dec 2005
Location: India & Singapore
Distribution: Vector linux, Debian
Posts: 42

Rep: Reputation: 15
sed error


hi guys,

I am getting this error when i use sed in shell script, but the same works in command line.

echo "/home/xyz/abc" | sed 's/\//\/\\/g'

same command, when i try in shell script it doesnt works
--- shell script------
path=/home/xyz/abc
somepath=`echo $path | sed 's/\//\/\\/g'`
-----------------------

I am getting this error
sed: -e expression #1, char 10: unterminated `s' command

Kindly help me

Thanks in advance
 
Old 05-16-2008, 07:43 PM   #2
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Hey There,

With the variable assignment, you've got another level of escaping to do, and, admittedly, it can get confusing Sometimes a good idea is to use a substitute character for the delimiter (like %, so you would write sed 's%this%that%') to reduce confusion.

In any event, this should do it for you

Quote:
-bash-3.2$ echo $path | sed 's/\//\/\\/g'
/\home/\xyz/\abc
-bash-3.2$ somepath=`echo $path | sed 's/\\//\\/\\\/g'`
-bash-3.2$ echo $somepath
/\home/\xyz/\abc

Best wishes,

Mike
 
Old 05-17-2008, 12:04 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by morphixrocks View Post
hi guys,

I am getting this error when i use sed in shell script, but the same works in command line.

echo "/home/xyz/abc" | sed 's/\//\/\\/g'

same command, when i try in shell script it doesnt works
--- shell script------
path=/home/xyz/abc
somepath=`echo $path | sed 's/\//\/\\/g'`
-----------------------

I am getting this error
sed: -e expression #1, char 10: unterminated `s' command

Kindly help me

Thanks in advance
Code:
somepath=$(echo $path | sed 's/\//\/\\/g')
works as expected ...


Cheers,
Tink
 
  


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
sed error : Unknown option to 's' powah Linux - General 4 01-04-2012 02:52 PM
sed error sharathkv25 Programming 4 03-30-2007 01:01 AM
sed error ShaqDiesel Programming 4 01-19-2007 12:18 PM
sed -f: error nano_mag Linux - Newbie 3 05-15-2005 07:51 PM
sed substitution error BlkPoohba Programming 1 08-25-2004 02:00 PM

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

All times are GMT -5. The time now is 09:47 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