replacing two EOL chars by one
Bill Kelly
billk at cts.com
Sat Dec 20 16:06:12 EST 2003
"Xah Lee" <xah at xahlee.org> wrote:
> i have a bunch of java files that has spaced-out formatting that i
> want to get rid of. I want to replace two end of line characters by
> one end of line characters. The files in question is unix, and i'm
> also working under unix, so i did:
>
> perl -pi'*~' -e "s@\n\n@\n at g" *.java
>
> but this to no avail.
Here are two Ruby solutions, both of which have Perl equivalents:
ruby -i~ -e '$/=nil; puts gets.gsub(/\n\n/,"\n")' *.java
ruby -i~ -e '$/="\n\n"; while(gets)do puts chop end' *.java
You may also want to check out http://astyle.sourceforge.net/
which is a free source code beautifier for C/C++/Java.
> after many minutes of checking and rechecking and lots of trial and
> error with frustration, i realized that the fucking perl to my
> expectations again cannot do this simple fucking thing. Nor can the
> unix utility tr. Fucking stupid perl couldn't do a simple task of
> replacing strings.
>
> let me just take this opportunity to explain one shit from the
> thousands from perldoc. [...]
http://www.wavlist.com/movies/135/str-francis.wav
"Lighten up, Francis."
Regards,
Bill
More information about the Python-list
mailing list