 <p>you can use awk as well</p> <pre><code>$ echo 'Some - String- 12345-' | awk -F" *- *" '{$1=$1}1' OFS="-" Some-String-12345- </code></pre> <p>if its just "- " in your example</p> <pre><code>$ s="Some- String- 12345-" $ echo ${s//- /-} Some-String-12345- </code></pre>