I have tried

echo "ABCDE-123456" | sed 's/-//' | sed 's/./& -/g'
A -B -C -D -E -1 -2 -3 -4 -5 -6 -

sed is not putting the - on the first character. How can I make it output

-A -B -C -D -E -1 -2 -3 -4 -5 -6 `

  • what about sed 's/./-& /g' ? – pLumo Dec 10 '18 at 10:19

You can turn around your sed replacement string to be -&.

Also, no need to call sed twice as you can combine multiple commands with ;.

sed 's/-//; s/./-& /g'

Note, that you will have a space at the end which you might need to get rid of.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.