I want to make a shell script (bourne)

I want to make a script in order to strip the last spaces of ever line of my file
for example I have:
jjj@hotmail.com_ _ _ _ _ _
kk23@hotmail.com_ _ _ _ _
luuu78a@hotmail.com_ _ _
and I would like to have as result the following:
jjj@hotmail.com
kk23@hotmail.com
luuu78a@hotmail.com
vage78Asked:
Who is Participating?
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.

sunnycoderCommented:
Hi vage78,

sed -e 's/ *$//' input_file > output_file
mv -f output_file input_file

Cheers!
Sunny:o)
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
vage78Author Commented:
Hi  sunnycoder
Can you please explaine me the parameters of your command?
Thank you
0
sunnycoderCommented:
sed -e 's/ *$//' input_file
          ^    ^
search and replace: all space characters at the end of the line with NULL ... this is simple sed syntax
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

vage78Author Commented:
Hi sunnycoder
I forgot to tell you that The character I wrote with the sign _ is
space character. I don't know if this would change your command
0
sunnycoderCommented:
I knew that
sed -e 's/ *$//' input_file
             ^ this is space char here
0
vage78Author Commented:
In order to reconfirm what we said
1)I want to cutt of the spaces which exist an at every line at the last positions of every line (after every email address)
2)What exactly does *$
3) why you are using mv -f output_file input_file

0
sunnycoderCommented:
I suggest you try running the script

1)I want to cutt of the spaces which exist an at every line at the last positions of every line (after every email address) --- this is what the script does
2)What exactly does *$
it means all instances of space followed by end of line
3) why you are using mv -f output_file input_file
sed will produce output /edited file to stdout .. we redirect it to another file and then replace input file with it
0
TintinCommented:
Hi vage78.

Perhaps I can clarify some of your questions about sunnycoder's solution.

Where, sunnycoder wrote:

sed -e 's/ *$//' input_file > output_file
mv -f output_file input_file


I would write it as

sed 's/ *$//' input_file >output_file  && mv output_file input_file

The -e option on sed is not needed if you are just doing a single replacement and the -f flag on mv is not needed either.

So the sed regular expression translates to:

' *' - means match zero or more spaces
'$' - means match the end of the line

so putting it together, it is matching zero or more spaces to the end of the line.  This is then replaced with nothing, effectively deleting them.



0
sagar24Commented:
HI
I think below swd command will give you the desired output
sed 's/ .*$//g' inputfile >output file

Regards
 sagar

           
0
TintinCommented:
sagar24.

Your solution won't work as it will match the first space and delete everything up to the end of the line.
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.

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.