Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to remove whitespaces in pipe delimited string using sed

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#!/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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading