replacing two EOL chars by one

S

Sara

(e-mail address removed) (Xah Lee) 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@g" *.java
:
: but this to no avail.

Of course it's not.

Perl's -p switch processes one line at a time. A line cannot have more
than one newline character.

Perl's "paragraph" reading might be useful to you, where any number of
consecutive newline characters mark the end of a record. See "$/" in
perlvar for details.

perl -i'*~' -lpe "BEGIN{$/=''}" *.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.

Complete nonsense. Don't blame your own incompetence on Perl.

: Fucking stupid perl
: documentation and Larry Wall moron who is i believe incapable of
: writing clearly and logically in English masquerading as humor.

If you feel you can explaint it more clearly, quit bellyaching about it and
submit a documentation patch.

Preferrably one that is less petulant and profane than your article.
Frustration is no excuse for incivility.

is incivility a word? Curious. Anyhow, if I understand this you want
to replace two \n's with one? How about this (untested) code:

die "Perl is ever so much smarter than Java\n" unless open F,
'myfile';
my @f = <FILE>
close F;

$f = join '',@f;
$f =~ s/(\n)\n/$1/gs;

die "Hmm this file cant be opened for writing\n" unless open F,
'>myfile';
print F $f;
close F;

print "Perl does it again!\n\n";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top