"Inserting" a line in a text file?

William Park opengeometry at NOSPAM.yahoo.ca
Tue May 7 17:25:19 EDT 2002


William Park <opengeometry at yahoo.ca> wrote:
> On Tue, May 07, 2002 at 09:34:02PM +0100, Duncan Smith wrote:
>> I need to (in effect) insert a single line at the beginning of an
>> existing text file (a dumped MySQL database, so potentially large).  Is
>> there anything cuter than  eg. creating a temporary file containing the
>> single line, reading the lines from the data file, appending them to the
>> temporary file, deleting the data file, renaming the temporary file?
>> Currently on Win2000, but the solution needs to be cross platform.  I can
>> always go with the obvious, but something faster and / or simpler would
>> be nice (I might even learn something).  Cheers.  TIA.
> 
> Well, that's how I would do it... but, I'm on Linux.

If you have access to 'ed' or 'vi', then you can insert using the text
editors.  Eg.

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin



More information about the Python-list mailing list