Multiple substitutions in one expression using sed
Hi, I'm trying to get multiple substitutions in one expression using sed:
Code:
echo "--_----__-___-_-__-" | sed -e "s/[_-|-_|--]/-/g" But I'm getting an errors. |
So you have marked the question as solved, does this mean you worked it out? If so, why not share your new found wisdom so others may benefit.
Also, if you are getting errors, it would be prudent to show the errors otherwise how do we know how to help? |
Quote:
Code:
-----__--_- but if you run sed with three substitutions in separate expressions you will get another result: Code:
----_-- |
Well my first issue would be that you have posted what you started with and what solution you tried to use, but at no point do you show what your desired output should be?
I also have issues with the question as well as your proposed solution: 1. The question :- replace all instances of _-, -_, -- with - (dash) ... my issue here is, should the solution be recursive, ie based on the first 3 characters of your example '--_', now if recursive the solution would first replace the first 2 dashes with a single dash and then on the next pass it will change the now single dash and an underscore to be a single dash, hence these 3 characters would become simply ... '-' ... is this correct? 2. Proposed solution :- [_-|-_|--] ... this part of your regex says, look for a dash, a pipe or an underscore ... the fact that you have used patterns is irrelevant as the square brackets have indicated you will show a group of individual characters or a group, such a-z, where any one of those characters can be replaced by your dash. You may have meant something more akin to: Code:
sed -r 's/--|-_|_-/-/g' So as said initially, if you show us the desired output it can greatly help us to help you in coming up with a solution. |
Quote:
Quote:
|
Quote:
|
If you do not know what you want as the output I can see no logical solution. As I have pointed out there are multiple options depending on the output you want.
|
All times are GMT -5. The time now is 06:16 PM. |