| View previous topic :: View next topic |
| Author |
Message |
Don Dailey
Joined: 29 Apr 2008 Posts: 4325
|
Post subject: Re: looking for a tool to conver line endings Posted: Thu Mar 22, 2012 2:15 pm |
|
|
| lucasart wrote: |
| rvida wrote: |
Thanks for all the answers.
I decided to use the sed based solution. It is a wonderful tool, although for people coming from Dos/Windows world the syntax is somewhat obscure...
Btw. after some googling I found a list of very useful sed one liners:
http://sed.sourceforge.net/sed1line.txt |
Yes, it's true that regular expressions aren't easy at first. But once you understand how they work, they are so powerful. It's amazing the amount of stuff one can do with grep and sed.
Perl is even more powerful and can do it all, but again one has to learn how to use it. Anyway, whether sed, perl, awk(?), many paths lead to Rome  |
I suggest to Richard that you could just learn Perl and be done with it. Perl has powerful regular expressions, is a full scripting language and is just about as expressive as any language can be. You could write one-liners on the command line (without getting out the editor) with the -e switch which will do amazing things. And when a one-liner is not quite enough Perl let's you do amazingly powerful stuff in just a few lines of code.
Your problem for example is solved like this using perl:
perl -e 'while (<>) { s/\s+$//; print $_."\n"; }' <win.txt > unix.txt
This assumes you run this script from unix. It will take all the white space out of the end of each line and then re-print it with the unix "\n" line ending.
I believe a way that would work on both windows and unix is this:
perl -e 'while (<>) { s/\s+$//; print $_ . chr(10); }' <win.txt > unix.txt
Don _________________ The Optimist thinks this is the best of all possible worlds, the Pessimist fears it is true. |
|
| Back to top |
|
 |
|
| Subject |
Author |
Date/Time |
looking for a tool to conver line endings |
Richard Vida |
Sun Mar 18, 2012 2:28 pm |
Re: looking for a tool to conver line endings |
Horacio Montenegro |
Sun Mar 18, 2012 2:44 pm |
Re: looking for a tool to conver line endings |
Ignacio Garcia |
Sun Mar 18, 2012 3:16 pm |
Re: looking for a tool to conver line endings |
Lucas Braesch |
Sun Mar 18, 2012 3:30 pm |
Re: looking for a tool to conver line endings |
Robert Hyatt |
Sun Mar 18, 2012 4:03 pm |
Re: looking for a tool to conver line endings |
Ignacio Garcia |
Sun Mar 18, 2012 5:42 pm |
Re: looking for a tool to conver line endings |
Robert Hyatt |
Mon Mar 19, 2012 3:43 am |
Re: looking for a tool to conver line endings |
Horacio Montenegro |
Sun Mar 18, 2012 5:08 pm |
Re: looking for a tool to conver line endings |
Richard Vida |
Sun Mar 18, 2012 6:29 pm |
Re: looking for a tool to conver line endings |
Ignacio Garcia |
Sun Mar 18, 2012 7:07 pm |
Re: looking for a tool to conver line endings |
Sven Schüle |
Sun Mar 18, 2012 11:10 pm |
Re: looking for a tool to conver line endings |
Ignacio Garcia |
Mon Mar 19, 2012 12:37 am |
Re: looking for a tool to conver line endings |
Horacio Montenegro |
Mon Mar 19, 2012 3:45 am |
Re: looking for a tool to conver line endings |
Sven Schüle |
Mon Mar 19, 2012 10:37 am |
Re: looking for a tool to conver line endings |
Robert Hyatt |
Mon Mar 19, 2012 3:47 am |
Re: looking for a tool to conver line endings |
Sven Schüle |
Mon Mar 19, 2012 10:58 am |
Re: looking for a tool to conver line endings |
Ignacio Garcia |
Mon Mar 19, 2012 11:54 am |
Re: looking for a tool to conver line endings |
Lucas Braesch |
Thu Mar 22, 2012 12:58 pm |
Re: looking for a tool to conver line endings |
Don Dailey |
Thu Mar 22, 2012 2:15 pm |
Re: looking for a tool to conver line endings |
Gary |
Thu Mar 22, 2012 3:25 pm |
Re: looking for a tool to conver line endings |
Don Dailey |
Thu Mar 22, 2012 4:22 pm |
Re: looking for a tool to conver line endings |
Don Dailey |
Mon Mar 19, 2012 1:52 pm |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|