Stripping out more than a space from a line, but keep single space.

Hi all,

Is there a way to perform the above, I am trying to strip out more than one space from a line, but keep the single space. See below output example.

My   Name is test  test2 test3  test4 test5
My Name is test test2 test3 test4 test5

Please note that the lines would contain different text, so that pattern match cannot be done using name from the text.

Thanks

Try this,

sed  -r "s/[ ]+/ /g" file
tr -s '  '.  

Use the above command
This is used to squeeze the repeated space character into a single character.
So repeated space character will become as single space.
And it wont affect the single space.

Example:

echo "My   Name is test  test2 test3  test4 test5" | tr -s ' '

The output is

My Name is test test2 test3 test4 test5

Try This

cat filename | tr -s ' '
or
tr -s ' ' < filename

Another one:

awk '$1=$1' file

vi

:%s/  */ /g

vim

:%s/\s+/ /g

sed

sed -e 's/  */ /g' file

Perl

perl -pe 's/(\s)+/$1/g' file
awk '$1=$1'
sed 's/  */ /g'
sed 's/[[:space:]]\{2,\}/ /g'

thks guys.....u all are great.