Remove of extra spaces from the trailing

HI,
I need the help from the experts like I have created one file with text like:

a  b c d
e  f  g h
i   j   k l

So my question is that i have to write the script in which like in the first sentence it will take only one space after d and remove all the extra space in the end.I dont wanna delete header and in between spaces

same in the second line it will take one space after h and remove all the extra space from the end.

same for the third one......

Please suggest some solution asap.

First, there's no need to shout, not even in the subject.
Second, don't double post.
Third, we're all volunteers, so demanding a solution "asap" without showing any effort of your own won't get you an answer any faster. If it's critical, post in the Emergency Forum. Otherwise be aware that, as volunteers, we provide help when we can and feel like it.

If you can't accept that and just want someone to do your work, go and hire someone.

hey I am new to this forum and I am unable to do this problem thats why I am asking this question and moreover the basic purpose of this forum is to get the solution so there is no harm in giving the solution and sorry for writing two times..

Yes, you're new. But so are a lot of other users, and most of them ask specific questions about parts where they're stuck and provide the steps they've tried, instead of just demanding an answer. And where did you read that this forum is here to provide you with complete solutions? We're here to help with problems, that's true, but that means helping you to help yourself: teaching you how to ask questions correctly, teaching you how to analyze problems, ...

What programs/commands do you think would be helpful with your problem? Have you tried any of them? If so, what did go wrong? If not, why not?

ok Thanks a lot for telling actually I am using sed command.

$ cat input.txt | sed 's/[ \t]*$//' > output.txt

but it is removing all the space from the end and i want one space to be there at the end.So here I got stuck so can u help me out in solving this problem.

See, was that so hard?

Try this: instead of just removing all whitespace at the end, replace them with a single whitespace. That's what the substitute command is for.

sed 's/[ \t]*$/ /' input.txt > output.txt

Actually I never use unix thats why its hard for me and thanx for replying.But will it make a single space between each and every character or is it for the end like in the end it should have a single space. for example

i/p: abc~d~~~

~ it indicates space so what i want to do is I need that after d it should take single space only and all others should remain same:

so o/p should be

o/p : abc~d~

Try with this ..

$ sed 's,.$,,g' infile

Have you tried the code I gave? The regex given will only match at the end of the line (that's what the '$' at the end means), and only whitespaces/tabs. So yes, it will remove only the whitespaces at the end, save one.