Solaris remove empty space from text file lines

I have a text file in Solaris 10. Sample lines of the text file is attached. It is comma separated line (two field in each line separated by a comma).

But each line's field contents have large number of leading/trailing empty spaces. I could use command to delete empty line:
perl -ni -e 'print if /\S/' /home/.../myfile.txt

How can I write a command that will delete all the leading/trailing blank spaces in each field?  sample.txt
toookiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SuperdaveCommented:
perl -ni -e 's/^ *//; s/ *$//; print if /\S/'   /home/.../myfile.txt
0
wesly_chenCommented:
sed s/"\s"//g myfile.txt > myfile1.txt
0
SuperdaveCommented:
Wait, I was too quick and didn't read the sample data; ignore that and I'll try again...
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

SuperdaveCommented:
Okay...
perl -ni -e 's/ *,/,/; s/ *$//; print if /\S/' sample.txt

A little simplistic--if the real data contain commas in quotation marks it might need enhancing.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
toookiAuthor Commented:
Thank you all.
perl -ni -e 's/ *,/,/; s/ *$//; print if /\S/' sample.txt
The above query mostly works for me.
Could you Superdave, please explain a line about how the command works.?
0
SuperdaveCommented:
I started with what you had, but before printing the line, modified it with the two substitution commands.

s/ *,/,/

means replace any number of spaces followed by a comma, with a comma.  (* means any number of the preceding thing.)

s/ *$//

means replace any number of spaces up to end-of-line with nothing.  ($ means end of line).

Semi-colon separates commands.
0
toookiAuthor Commented:
Thank you very much. I understand now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.