From: Thomas Jollans on
On Thursday 12 August 2010, it occurred to Dlanor Slegov to exclaim:
> Hi,
>
> I am dealing with very large text files (a few million lines) and would
> like to check and modify them according to a well defined format. The
> format requires ONLY ONE NEWLINE (followed by some sort of text) on top of
> the file and NO NEWLINE in the very end. The input files can be very
> diverse, such as one file may have 2 newlines on top and none in the end
> or other may not have a newline on top and 5 in the end.
>
>
> The aim is to check these files & introduce JUST ONE NEWLINE in the TOP and
> NO NEWLINE in the BOTTOM.
>
> Any pointers will be appreciated.

If the files are that long, you might want to avoid storing the whole file in
memory at the same time.

Have you already tried writing the program? If not, go write the program! (and
then come back, possibly, if you have questions)


PS: What a strange format that must be. Everybody agrees that text files
should end with a line feed, because some text editors might mess up if they
don't.
From: Steven D'Aprano on
On Thu, 12 Aug 2010 21:25:59 +0200, Thomas Jollans wrote:

> Everybody agrees that text files
> should end with a line feed, because some text editors might mess up if
> they don't.

For some definition of "everybody". Obviously the text editors which
DON'T mess up don't make the assumption that all text files end with a
newline.


--
Steven