LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-29-2012, 03:39 AM   #1
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Rep: Reputation: Disabled
sed error


Can somebody please suggest why i am getting below error in sed command while doing the basic substitution

echo "sunday"|sed 's/sunday/night'
sed: -e expression #1, char 14: unterminated `s' command
 
Old 10-29-2012, 04:04 AM   #2
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,818
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
You need to terminate the s command with the closing /
 
Old 10-29-2012, 04:21 AM   #3
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Original Poster
Rep: Reputation: Disabled
Thanks
 
Old 10-29-2012, 04:23 AM   #4
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Original Poster
Rep: Reputation: Disabled
One more thing , can you suggest or give an example which will help me in understand that when to use "-e" option in sed

eg:- sed -e "s/ddd/ee/g"

i am not able to establish the situation in which i can use this... pls help
 
Old 10-29-2012, 05:53 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,358

Rep: Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799Reputation: 2799
Do 2 or more changes to the same line.
 
Old 10-29-2012, 05:56 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
With sed's -e option you can string together multiple sed action's.

Consider this:
Code:
echo -e "Monday\nTuesday" | sed -e 's/Mon/Sun/' -e '/Tuesday/d'
Sunday
The above changes Mon to Sun (blue part) and also looks for lines that contain Tuesday and deletes them (green part). You cannot do this in one action, two are needed. You need the -e option for this (or use 2 seperate sed statements, which is not always possible).

There is one thing that you need to be aware of; Changes made in the first action are noticed in the second (third, ... ) action. Have a look at this simple silly example:
Code:
echo "sunday" | sed -e 's/sunday/night/' -e 's/night/week/'
week
The first action looks for sunday and changes this into night, the second action looks for night and changes this into week.

Have a look at this link as well: Sed - An Introduction and Tutorial
 
1 members found this post helpful.
Old 10-30-2012, 12:46 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
To be more exact, sed takes one line at a time into its 'pattern buffer' and attempts to apply all of the given expressions to it, in the order given. Then moves on to the next line and does the same thing.

To restrict an action to only specific lines, you usually use addressses in front of the expressions. You can also create nested expressions in '{}' brackets for complex actions. Multi-line work can get even more complex than that.

BTW, in most seds you can usually use a semicolon to separate expressions instead of using individual -e options.

Code:
$ echo -e "sunday morning\nmonday morning" | sed '/sunday/ s/morning/night/ ; /monday/ s/morning/afternoon/'
sunday night
monday afternoon
Here are a few useful sed references:
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/grabbag/
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt

Last edited by David the H.; 10-30-2012 at 12:51 PM. Reason: A better example
 
Old 10-31-2012, 02:24 PM   #8
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Original Poster
Rep: Reputation: Disabled
Thanks all for helping out
 
  


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
script.pl with sed shell calls: sh error syntax error near unexpected token `(' MMaddoxx Programming 7 11-24-2011 09:00 AM
sed error morphixrocks Linux - General 2 05-17-2008 01:04 AM
sed error sharathkv25 Programming 4 03-30-2007 02:01 AM
sed error ShaqDiesel Programming 4 01-19-2007 01:18 PM
sed -f: error nano_mag Linux - Newbie 3 05-15-2005 08:51 PM


All times are GMT -5. The time now is 04:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration