delete the last hyphen

I want to check for more than one hyphen and then hold the first one and delete the rest of the hyphen.
I try something like this sed 's/\([-]\)\1/\1/' but this doesn't work.
I try something like this sed 's/\([a-z]
\)-\1/ \1/g' but here the script delete all the hyphen.
I want to go from this : I want-to check for-more than one-hyphen.
to this : I want-to check for more than one hyphen.

Thanks anyway

echo "I want-to check for-more than one-hyphen." | perl -pe 's/-/\x0/;s/-/ /g;s/\x0/-/'
1 Like
echo "this is-a hyphen,oh oh one more-hyphen"|sed -r 's/(.*-.*)-/\1 /'

output:

this is-a hyphen,oh oh one more hyphen

1 Like