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 |
You need to terminate the s command with the closing /
|
Thanks
|
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 |
Do 2 or more changes to the same line.
|
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' 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/' Have a look at this link as well: Sed - An Introduction and Tutorial |
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/' http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt |
Thanks all for helping out
|
All times are GMT -5. The time now is 09:10 AM. |