From: Xah Lee
Subject: replacing two EOL chars by one
Date: 
Message-ID: <7fe97cc4.0312201204.7accda32@posting.google.com>
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 ··@····@··@g" *.java

but this to no avail.

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.
The following is a excerpt from perlre:

 m  Treat string as multiple lines. That is, change "^" and "$" from
    matching the start or end of the string to matching the start or
end
    of any line anywhere within the string.

 s  Treat string as single line. That is, change "." to match any
    character whatsoever, even a newline, which normally it would not
    match.

Note the first sentences of the two, which are logical opposites, but
in fact they are sinister and not opposite at all. Fucking stupid perl
documentation and Larry Wall moron who is i believe incapable of
writing clearly and logically in English masquerading as humor.

Now may i ask those who wallow in unix and perl: How do you do this?

(if the answer is to write a more elaborate program in perl that
explicitly open files and tread lines, please don't bother answering.
Unix util answer also welcome. (this message is cross posted to python
and scheme and ruby groups because i want them to know the
incompetence and sham aspects of perl. (or my opinions thereof.)))

Thanks.

 Xah
 ···@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html

From: Greg Menke
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <m3y8t7q8fw.fsf@europa.pienet>
···@xahlee.org (Xah Lee) writes:

> 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:

Have a look at tr and sed.  tr is also a handy tool for fixing Windows
cr/lf madness.

Gregm
From: Paul McGuire
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <yt2Fb.239044$do1.177693@twister.austin.rr.com>
Is this language really necessary?  I'm sure I've used these words myself,
but they're certainly not appropriate in a public discussion.

I do not know the answer to your question, it really seems more like a
regexp question, rather than a problem with Perl.  I hope someone who knows
the answer can respond, hopefully in more civil language.
From: Gunnar Hjalmarsson
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <bs2d7a$8uee9$1@ID-184292.news.uni-berlin.de>
Paul McGuire wrote:
> I hope someone who knows the answer can respond, hopefully in more
> civil language.

I'm sure that quite a few people know the answer, but most of them
have probably killfiled or decided to ignore him.

I hope that nobody provides an answer.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
From: Rahul Jain
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <8765gbqjfc.fsf@nyct.net>
Gunnar Hjalmarsson <·······@gunnar.cc> writes:

> Paul McGuire wrote:
>> I hope someone who knows the answer can respond, hopefully in more
>> civil language.
>
> I'm sure that quite a few people know the answer, but most of them
> have probably killfiled or decided to ignore him.
>
> I hope that nobody provides an answer.

And it's crossposted to numerous groups that have nothing to do with
perl.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Pascal Bourguignon
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <877k0rgdff.fsf@thalassa.informatimago.com>
"Paul McGuire" <·····@austin.rr.com> writes:

> Is this language really necessary?  I'm sure I've used these words myself,
> but they're certainly not appropriate in a public discussion.

We don't get  the usenet "in color" around here, so  I guess that this
languages reflected the fuming hot  in frustration state of the OP.  I
guess  that  you  could  measure  the  quality of  a  design  and  its
documentations by  the inverse  of the number  of posts related  to it
using such language.

When we'll  have video-usenet, I  guess language will be  more proper,
but we'll  be seeing  keyboads and screens  flying out of  the windows
more often.


> I do not know the answer to your question, it really seems more like a
> regexp question, rather than a problem with Perl.  I hope someone who knows
> the answer can respond, hopefully in more civil language.

Even with sed I find difficult to do that.


On the other hand, with emacs it's quite simple:

M-x replace-string RET C-q C-j C-q C-j RET C-q C-j RET
     
-- 
__Pascal_Bourguignon__                              .  *   * . * .* .
http://www.informatimago.com/                        .   *   .   .*
There is no worse tyranny than to force             * .  . /\  (   . *
a man to pay for what he does not                    . .  / .\   . * .
want merely because you think it                    .*.  / *  \  . .
would be good for him. -- Robert Heinlein             . /*   o \     .
http://www.theadvocates.org/                        *   '''||'''   .
SCO Spam-magnet: ··········@sco.com                 ******************
From: Jesse Tov
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <slrnbua1tp.qaq.tov@tov.student.harvard.edu>
Pascal Bourguignon <····@thalassa.informatimago.com>:
> Even with sed I find difficult to do that.

If you want to remove blank lines, then sed '/^$/d' will do.  If, on
the other hand, you actually want to compress pairs of newlines into
single newlines (as I think the specification may have said), something
a bit more complicated is required.  I think that sed 'N;P;/\n$/d;D'
will do it.

Jesse
From: Jesse Tov
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <slrnbua6h6.qaq.tov@tov.student.harvard.edu>
Pascal Bourguignon <····@thalassa.informatimago.com>:
> Even with sed I find difficult to do that.

If you want to remove blank lines, then sed '/^$/d' will do.  If, on
the other hand, you actually want to compress pairs of newlines into
single newlines (as I think the specification may have said), something
a bit more complicated is required.  I think that sed 'N;P;/\n$/d;D'
will do it.

If you want to use Perl or Ruby, these are equivalent to the first sed
solution:

    ruby -ne 'print unless /^$/'
    perl -ne 'print unless /^$/'

In Ruby you might also use:

    ruby -pe 'next if /^$/'

The equivalent doesn't work in Perl, probably because -p puts the
implicit print statement in a "continue" block, which gets executed
before the loop is restarted by "next".

If you're doing this on a huge file and care about speed, sed will
be slightly faster than Perl and Perl will blow Ruby away.  Because
I was curious, I tried writing it in C to see if I could beat sed.
My first attempt was slightly slower (!), but my second attempt ran
much faster than sed; unfortunately, it also took 30 minutes and
34 lines.

Jesse
From: Ragnar Hafsta�
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <bs2cdu$759$1@news.simnet.is>
"Xah Lee" <···@xahlee.org> wrote in message
·································@posting.google.com...
> 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 ··@····@··@g" *.java
>
> but this to no avail.
>
snipped long rant about perldocs

the problem is not your understanding of  regular expressions,
but rather that you are forgetting what -p does
you are applying the -e commands to each line of input in turn before
printing it. no line of the input contained \n\n as then they would not
have been ONE line.

now, to do what you want, try:
perl -0 -pi'*~' -e ··@····@··@g' *.java
From: Xah Lee
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <7fe97cc4.0312210106.5a72c199@posting.google.com>
Ragnar Hafsta? (·····@simnet.is) wrote:

 > you are forgetting what -p does
 > ...
 > perl -0 -pi'*~' -e ··@····@··@g' *.java

Thank you kindly.

--

Now there are a slew of perl driviling morons who
has also participated in answering to no avail. Die!

PS pasted below my sig is some meat about unix. Unix morons please
slurp and spruce it up and place it on wikipedia.org or something.

 Xah
 ···@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



From: 	  ···@xahlee.org
Subject: 	unix inanity: shell env syntax
Date: 	June 7, 2002 12:00:29 AM PDT
To: 	  ···········@omnigroup.com

Unix Syntatical and Semantical Stupidity Exposition.
(this is one of the many technical expositions of unix stupidity)

(this is currently unpolished, but the meat is there. Input welcome.)
------------
arguments are given with a dash prefix.
e.g.
ls -a -l

order (usually) does not matter. So,
ls -a -l
is the same as
ls -l -a

but arguments can be combined

e.g.

ls -al
means the same thing as
ls -a -l

However, some option consists of more than one character.
e.g.,

perl -version
perl -help

therefore, the meaning of an option string "-ab" is ad hoc dependent
on the program. It can be "-a -b" or just an option named "ab".

Then, sometimes there are two versions of the same optional argument.
e.g.

perl -help
perl -h

perl -version
perl -v

this equivalence is ad hoc.

Different program will disagree on common options. For example, to get
the version, here are common varieties

-v
-V
-version

sometimes v/V stands for "verbose mode", i.e. to output more detail.

Sometimes, if an option is given more than once, then it specifies a
degree of that option. For example, some command accept the -v for
"verbose", meaning that it will output more detail. Sometimes there
are few levels of detail. The number of times an option is specifies
determines the level of detail.
e.g. on Solaris 8,

/usr/ucb/ps -w
/usr/ucb/ps -w -w

thus, meaning of repeated option may have special meaning depending on
the program.

oftentimes some options automatically turn on or supress a bunch of
others. e.g.
Solaris 8, /usr/bin/ls -f

--
when a named optional parameter is of a boolean type, that is a toggle
of yes/no, true/false, exist/nonexist, then it is often times that
instead of taking a boolean value, their sole existance or
non-existance defines their value.

toggle options are sometimes represented by one option name for yes,
while another option name for no, and when both are present, the
behavior is program dependent.
--

toggle option are represented by different option names
--

for named options, their syntax is slack but behavior is usually
dependent on the program.
i.e. not all of the following works for every program
command -o="myvalue"
command -omyvalue
comand -o myvalue

--

often one option may have many synonyms...

--
an example of a better design... (Mathematica, Scheme, Dylan, Python,
Ruby... there's quite a lot elegance and practicality yet distinct
designs and purposes and styles ...)

(recall that unix does not have a bad design to begin with; it's a
donkey shit pile from the beginning and continuation. Again, unix is
not simply technically incompetent. If that, then that's easy to
improve, and i don't have a problem with, since there are things in
one way or another considered horrendous by today's standard like
COBOL or FORTRAN or DOS etc. But, unix is a brain-washing idiot-making
machine, churning out piles and piles of religiously idiotic and
pigheaded keyboard punchers. For EVERY aspects of good engineering
methodology improvement or language design progress opportunity,
unixers will unanimously turn it down.

inevitably someone will ask me what's my point. My point in my series
of unix-showcasing articles has always been clear for those who
studies it: Unix is a crime that caused society inordinate harm, and i
want unix geeks to wakeup and realize it.

 Xah
 ···@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html




From: 	  ···@xahlee.org
Subject: 	Re: mail handling/conversion between OSes/apps
Date: 	May 12, 2002 8:41:58 PM PDT
Cc: 	  ···········@omnigroup.com

...

Yes, unix have this beautiful philosophy. The philosophy is functional
programing.

for example, define

power(x) := x*x

so

power(3) returns 9.

here 'power' is a function that takes 2 arguments. First parameter
specifies the number to be raised to power, the second the number of
times to multiply itself.

functions can be nested,

f(g(h(x)))

or composed

compose(f,g,h)(x)

here the 'compose' itself is a function, which take other functions as
arguments, and the output of compose is a new function that is
equivalent to nesting f g h.

nesting does not necessarily involved nested syntax. Here's a post fix
notation in Mathematica for example:

x /. h /. g /. h

or prefix notation.

f @ g @ h @ x

or in lisp

(f (g (h x)))
--

the principle is that everything is either a function definition or
function application, and function's behavior is strictly determined
by its argument.

Apple around 1997 or so have this OpenDoc technology, which is similar
idea applied more broadly across OS. That is, instead of one
monolithic browser or big image editors or other software, but have
lots of small tools or components that each does one specific thing
and all can call each other or embedded in  an application framework
as services or the like. For example, in an email apps, you can use
BBEdit to write you email, use Microsoft's spell checker, use XYZ
brand of recorder to record a message, without having to open many
applications or use the Finder the way we would do today. This
multiplies flexibility. (OpenDoc was killed when Steve Jobs become the
iCEO around 1998 and did some serious house-keeping, against the
ghastly anger of Mac developers and fanatics, I'm sure many of you
remember this piece of history.)

The unix pipe syntax |, is a post-fix notation for nesting. e.g.

ps auwwx | awk '{print $2}' | sort -n | xargs echo

in conventional syntax it might look like this:
xargs(  echo, sort(n, awk('print $2', ps(auwwx)))  )

So when you use "pipe" to string many commands in unix, you are doing
supreme functional programing. That's why it is so flexible and
useful, because each component or function does one thing, and you can
combine them in myriad of ways. However, this beautiful functional
programing idea, when it is implemented by the unix heads, becomes a
fucking mess. Nothing works and nothing works right.

I don't feel like writing a comprehensive exposition on this at the
moment. Here's a quick summary:

* fantastically stupid syntax.

* inconsistencies everywhere. everywhere.

* fucking stupid global variables reliance called environment
variables, which fuck up the whole functional programing paradigm.

* implicit stuff everywhere.

* totally incompetent commands and their parameters. (promiscuously
non-orthogonal, and missing things, and fucked up in just more ways
than one can possibly imagine. there are one million way to do one
thing, and none are correct, and much simple needs CANNOT be done!
(that's why there are gazillion shells each smart-ass improving upon
the other, and that's why Perl is born too! But asinine Larry Wall
don't know shit but smugly created another complexity that don't do
much.))

maybe some other day when i'm pissed, i'll write a better exposition
on this issue. I've been wanting to write a final-say essay on this
for long. Don't feel like it now.

 Xah
 ···@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html
From: Matt Garrish
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <LRjFb.439$d%1.193083@news20.bellglobal.com>
"Xah Lee" <···@xahlee.org> wrote in message
·································@posting.google.com...
>
> Now there are a slew of perl driviling morons who
> has also participated in answering to no avail. Die!
>
> PS pasted below my sig is some meat about unix. Unix morons please
> slurp and spruce it up and place it on wikipedia.org or something.
>

Since you're obviously in need of an expanded vocabulary, I think you'll
find you can use the following to describe yourself nicely:

http://en.wikipedia.org/wiki/Script_kiddie

Matt
From: Steve Horsley
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <bs46uj$u9m$1@news.freedom2surf.net>
The boy's an idiot!
From: Ragnar Hafsta�
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <bs495e$fnf$1@news.simnet.is>
"Xah Lee" <···@xahlee.org> wrote in message
·································@posting.google.com...
> Ragnar Hafsta? (·····@simnet.is) wrote:
>
>  > you are forgetting what -p does
>  > ...
>  > perl -0 -pi'*~' -e ··@····@··@g' *.java
>
> Thank you kindly.
>
> --
>
> Now there are a slew of perl driviling morons who
> has also participated in answering to no avail. Die!
(snipped rather much more)

I apologise

gnari
From: J�rgen Exner
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <K2jFb.23141$jG4.357@nwrddc02.gnilink.net>
Xah Lee wrote:
[...]
> --
[246 lines of signature snipped]

That even beats any spammer I know of.
If your foul language wasn't reason enough yet, this really does it:

    *PLONK*

jue
From: Pascal Bourguignon
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <87vfoaf341.fsf@thalassa.informatimago.com>
···@xahlee.org (Xah Lee) writes:
> maybe some other day when i'm pissed, i'll write a better exposition
> on this issue. I've been wanting to write a final-say essay on this
> for long. Don't feel like it now.

Perhaps instead of losing you time with this, you would better use one
of the  other strengths of  unix: it's modularity, and  implement your
own shell, or try scsh (scheme  shell).  There, you don't have to mess
with sh idiosyncratic syntax: you just write pure lisp to combine your
commands.  There is also an easy way to replace to EOL chars by one in
scsh.


-- 
__Pascal_Bourguignon__                              .  *   * . * .* .
http://www.informatimago.com/                        .   *   .   .*
There is no worse tyranny than to force             * .  . /\  (   . *
a man to pay for what he does not                    . .  / .\   . * .
want merely because you think it                    .*.  / *  \  . .
would be good for him. -- Robert Heinlein             . /*   o \     .
http://www.theadvocates.org/                        *   '''||'''   .
SCO Spam-magnet: ··········@sco.com                 ******************
From: Bill Kelly
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <8R2Fb.23477$nG3.12519@twister.socal.rr.com>
"Xah Lee" <···@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 ··@····@··@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
From: J�rgen Exner
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <R03Fb.16875$jG4.10934@nwrddc02.gnilink.net>
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 ··@····@··@g" *.java
>
> but this to no avail.
>
> 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.
[rest of rant snipped]

Five seconds of thinking might have spared you from embarassing yourself
like that (and is certainly more effective than 5 paragraphs of swearing).
You are reading the file line by line. And with each line you are looking
for two consecutive newlines.
Now, how can a single line contain two newlines?

jue
From: Jay Tilton
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <3fe4bd0e.68951468@news.erols.com>
···@xahlee.org (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 ··@····@··@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.
From: Sara
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <776e0325.0312221317.6f7378f5@posting.google.com>
·······@erols.com (Jay Tilton) wrote in message news:<·················@news.erols.com>...
> ···@xahlee.org (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 ··@····@··@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";
From: ·······@Linux.ie
Subject: Re: replacing two EOL chars by one
Date: 
Message-ID: <3FE6B841.90707@Linux.ie>
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 ··@····@··@g" *.java

Of course you can do it in Perl.
The handiest way I think is:

tr -s '\n'

P�draig.