I have a String "980 Rafael" and I would like to know how I will remove only the spaces that are between the numbers in shell script.
I have a String "980 Rafael" and I would like to know how I will remove only the spaces that are between the numbers in shell script.
Take a look at the code below, remove the first blank space found.
echo "4 980 Rafael" | sed '0,/[[:blank:]]/s/[[:blank:]]//'
[[:blank:]]
is a POSIX regex class that removes whitespace, tabs ... for more information about this class, regex posix
output:
4980 Rafael
The Regex used works as follows:
0,/padrao/s/padrao/substituicao/
where padrao
is what will be replaced and substituicao
is what will replace, 0
at the beginning says that it is only the first occurrence.
Analogously to the response from @Mathias but with awk
inves sed
:
echo "4 980 Rafael" | awk '{sub(" ","")}1'
Give me an idea that the previous answers are only removing the first space (wherever it is) or be sed 's/ //'
I propose:
echo "... 4 434 Rafael" | sed -r 's/([0-9]) ([0-9])//'
that is: replace Num Num - > NumNum