Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script: Remove all the space characters in a string

Tags:

shell

I work on shell script and I want to remove all space characters in a string. On another question I saw a sed command for replacing and tried to use it with sending null character in it:

echo \0 | sed "s/ /${text}/"

But it did not work.

Any other way to do this?

like image 543
Bar Avatar asked Dec 06 '22 05:12

Bar


1 Answers

This deletes all space characters in the input:

echo some text with spaces | tr -d ' '

Another way using sed:

echo some text with spaces | sed -e 's/ //g'

But... In your example there are no spaces, and it looks like you want to replace spaces with the content of the variable $text... So not 100% sure this is what you're looking for. So if not, then please clarify.

like image 90
janos Avatar answered Feb 19 '23 14:02

janos