0

I have a string that can contain, between characters (other than spaces), one or more spaces.

I would like to replace an undetermined number of spaces by only one space.

Example:

3 root hadoop        332 2020-03-11 10:09

Becomes:

3 root hadoop 332 2020-03-11 10:09

or

3 root    hadoop   332 2020-03-11 10:09

becomes:

3 root hadoop 332 2020-03-11 10:09

How can I achieve this ?

Itération 122442
  • 2,644
  • 2
  • 27
  • 73

1 Answers1

0

You can use an array:

$ x=(3 root hadoop        332 2020-03-11 10:09)
$ echo ${x[*]}
3 root hadoop 332 2020-03-11 10:09
chash
  • 3,975
  • 13
  • 29