473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

replacing two EOL chars by one

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.

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
xa*@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
Jul 18 '05 #1
10 2464
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.
Jul 18 '05 #2
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

Jul 18 '05 #3
"Xah Lee" <xa*@xahlee.org> wrote in message
news:7f**************************@posting.google.c om...
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.

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 's@\n\n@\n@g' *.java


Jul 18 '05 #4

"Xah Lee" <xa*@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@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

Jul 18 '05 #5
Gunnar Hjalmarsson <no*****@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
rj***@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
Jul 18 '05 #6
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.

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
Jul 18 '05 #7
xa*@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 "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.

Jul 18 '05 #8

xa*@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
Jul 18 '05 #9
"Paul McGuire" <pt***@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: po********@sco.com ******************
Jul 18 '05 #10
Pascal Bourguignon <sp**@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
Jul 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dornick | last post by:
So I want to do the above, and I really, REALLY don't want to rewrite the entire file. I've been working on it for a while now, and can't for the life of me get it functioning. Basically, I want...
2
by: thehuby | last post by:
Isn't inserting good data and getting it out of a db a pain in the a$$? I am going to be using the Markdown text to HTML parser (http://daringfireball.net/projects/markdown/dingus) for creating...
1
by: Fabiano | last post by:
Please, i got an XML String that contains some special caracters like linefeed, tab and others. How can i replace this chars? Can i use an ASCII value at the XXX.replace() method? Tks in...
12
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
32
by: FireHead | last post by:
Hello C World & Fanatics I am trying replace fgets and provide a equavivalant function of BufferedInputReader::readLine. I am calling this readLine function as get_Stream. In the line 4 where...
16
by: Eric Lindsay | last post by:
I have a bunch of old web pages now in HTML 4.01 Strict I update every now and then with revised material. They were written back when using <a name=" was the normal method of including an anchor....
6
by: Andrew | last post by:
I am using an XmlSerializer to save some settings and I have discovered that when a string is saved containing a cr+nl it is replaced with just a newline when loading back in. I am no expert with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.