<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>I would greatly appreciate a python solution as this problem is only the head of a larger problem for which I am on a mission to write a FULL one-stop-shop python script. I am trying two things- iter() and fileinput module...</DIV>
<DIV>Thanks!<BR></DIV>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt">
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Tahoma>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Matty Sarro <msarro@gmail.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Dlanor Slegov <dlanorslegov@rocketmail.com><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Thu, August 12, 2010 5:22:58 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: Inserting/Deleting newline(s) in very large text files<BR></FONT><BR>
<META content=off http-equiv=x-dns-prefetch-control>
<DIV class=gmail_quote>On Thu, Aug 12, 2010 at 11:12 AM, Dlanor Slegov <SPAN dir=ltr><<A href="mailto:dlanorslegov@rocketmail.com" rel=nofollow target=_blank ymailto="mailto:dlanorslegov@rocketmail.com">dlanorslegov@rocketmail.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0pt 0pt 0pt 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>
<DIV>
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt">
<DIV>Hi,</DIV>
<DIV> </DIV>
<DIV>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. </DIV>
<DIV> </DIV>
<DIV>The aim is to check these files & introduce JUST ONE NEWLINE in the TOP and NO NEWLINE in the BOTTOM.</DIV>
<DIV> </DIV>
<DIV>Any pointers will be appreciated.</DIV>
<DIV> </DIV>
<DIV>Thanks,<BR>DS.</DIV>
<DIV>  </DIV></DIV><BR></DIV><BR>--<BR>http://mail.python.org/mailman/listinfo/python-list<BR><BR></BLOCKQUOTE></DIV><BR>If you're using a unix box you may want to look into sed.<BR>sed -i.<extensionofbackup> '1i text to be inserted in first line' <filename><BR><BR>For example:<BR>sed -i.bak '1i alias bond0 bonding' /etc/modprobe.conf<BR>Would back up the original file to the initial filename plus the extension .bak. Then it would insert:<BR>alias bond0 bonding<BR>into /etc/modprobe.conf<BR><BR>Into the 1st line of the file, moving everything else down one line.<BR><BR>You can find some info on dealing with newlines here:<BR>http://www.grymoire.com/Unix/Sed.html#toc-uh-nl<BR><BR>I know you're looking for a python solution, but this may be easier. Just a heads up.<BR>
<META content=on http-equiv=x-dns-prefetch-control></DIV></DIV></div><br>







      </body></html>