delete empty spaces greater that one between each column in a text file using shell script

I have the attached file. I need to have only one space separating columns but the format between some rows is messed up. How do I use shell do delete more than one space between columns?
Who is Participating?
ozoConnect With a Mentor Commented:
perl -i.bak -lpe 's/\s+/ /g' sample.txt
rbrideConnect With a Mentor Commented:
If you are using normal UNIX shell tools (also cygwin) etc, you can just do the following:

cat sample.txt | sed 's/\s\s*/ /g' > output.txt

You can also do it with perl:
perl -n -e '{ s/\s\s*/ /g; print "$_\n"; }' < sample.txt > output.txt
Basically in whatever language you use, there should be a find/replace. Replace any instance of two spaces with a single space. To also remove triple spaces, etc just keep doing the first step until it doesn't change anything.
Kamaraj SubramanianConnect With a Mentor Application Support AnalystCommented:
tr -s " " filename > outputfile

Open in new window

libertyforall2Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.