Prepending to a file

Discussion in 'Perl Misc' started by Dave, Jul 24, 2005.

  1. Dave

    Dave Guest

    I would like to write something at the begginging of a text file,
    without overwriting what is already there.

    i.e if the file 'foo' contains

    two
    three
    four

    I would like to be able to prepend 'one'

    so the file reads

    one
    two
    three
    four

    How is the best way to do this?

    On a UNIX sheel script I could do it by writing the new data (in this
    case the word 'one') into another file, then using cat

    But I am not sure how to do any of this in perl. I'm using a UNIX
    system, and Perl 5.8.6
     
    Dave, Jul 24, 2005
    #1
    1. Advertisements

  2. Gunnar Hjalmarsson, Jul 25, 2005
    #2
    1. Advertisements

  3. Dave

    Guest

    Dave wrote:

    > I would like to write something at the begginging of a text file,
    > without overwriting what is already there.


    See FAQ.
     
    , Jul 25, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia Muñoz
    Replies:
    3
    Views:
    1,616
    Scott Allen
    Jun 4, 2005
  2. Stefan Behnel

    Prepending to traceback

    Stefan Behnel, Feb 2, 2005, in forum: Python
    Replies:
    3
    Views:
    433
    Ian Bicking
    Feb 9, 2005
  3. Dave
    Replies:
    1
    Views:
    1,189
    Juan T. Llibre
    Jun 8, 2007
  4. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    Reading of file by next of map file and by next of file descriptor.

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 10, 2007, in forum: C++
    Replies:
    1
    Views:
    980
    Alf P. Steinbach
    Jul 10, 2007
  5. scad
    Replies:
    4
    Views:
    1,201
    James Kanze
    May 28, 2009
  6. Ludwigi Beethoven
    Replies:
    5
    Views:
    561
    Mike Hall
    Jul 26, 2003
  7. Serdar Kýlýç

    Array prepending nil object

    Serdar Kýlýç, Jan 31, 2006, in forum: Ruby
    Replies:
    3
    Views:
    196
    Serdar Kýlýç
    Jan 31, 2006
  8. Thomas Murphy

    Prepending string "@" to usernames

    Thomas Murphy, May 24, 2013, in forum: Python
    Replies:
    0
    Views:
    169
    Thomas Murphy
    May 24, 2013
Loading...