?
Solved

I want to make a shell script (bourne)

Posted on 2003-11-13
10
Medium Priority
?
352 Views
Last Modified: 2013-12-27
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
0
Comment
Question by:vage78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 80 total points
ID: 9738169
Hi vage78,

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

Cheers!
Sunny:o)
0
 

Author Comment

by:vage78
ID: 9738218
Hi  sunnycoder
Can you please explaine me the parameters of your command?
Thank you
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738231
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vage78
ID: 9738247
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738252
I knew that
sed -e 's/ *$//' input_file
             ^ this is space char here
0
 

Author Comment

by:vage78
ID: 9738671
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738699
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
 
LVL 48

Expert Comment

by:Tintin
ID: 9742425
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
 

Expert Comment

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

Regards
 sagar

           
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9791524
sagar24.

Your solution won't work as it will match the first space and delete everything up to the end of the line.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question