I have an input string which is a comma separated like this "Done, Completed, Closed" which I want to transform into like this using sed (stream editor) Done|Completed|Closed
The condition is there should not be any whitespaces in the final output string (Done|Completed|Closed).
An input string can be like this "Done, Completed, Closed" or "Done, Completed,Closed" or in any combination of whitespaces in between
I’m able to convert this comma separate to pipe separated but unable to remove the whitespaces from them.
#!/bin/bash
STRING="Done, Completed, Closed"
echo $(echo $STRING | sed -e 's/,/ |/g')
I just have to remove the whitespaces as well. I would really appreciate if someone please guide me in fixing this code?
>Solution :
Use this sed -e 's/ //g' at the end of your script.
#!/bin/bash
STRING="Done, Completed, Closed"
echo $(echo $STRING | sed -e 's/,/ |/g' | sed -e 's/ //g')