FAQ
Hello,
I am dealing with text files of sizes > 2 GB. I have to modify just the top 2 lines
of such files. Is there a way in Perl to modify just the first 'n' lines of the file
without having to process rest of the file as it involves a lot of IO and time.

Thanks,
Siva.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Search Discussions

  • John W. Krahn at Feb 6, 2003 at 10:53 pm

    Sashidhar wrote:

    Hello, Hello,
    I am dealing with text files of sizes > 2 GB. I have to modify just the top 2 lines
    of such files. Is there a way in Perl to modify just the first 'n' lines of the file
    without having to process rest of the file as it involves a lot of IO and time.
    It depends. If the modifications don't change the length of the file
    then you can do it. If the modifications increase or decrease the
    length of the file then you have to process the entire file.


    John
    --
    use Perl;
    program
    fulfillment
  • Sashidhar at Feb 6, 2003 at 10:59 pm
    I may have to change the length of the files. Is there no way, like manipulating the
    inode entries to reflect any changes in the length. Ofcourse, I realize that this is
    specific to the linux/unix env.

    --- "John W. Krahn" wrote:
    Sashidhar wrote:
    Hello, Hello,
    I am dealing with text files of sizes > 2 GB. I have to modify just the top 2 lines
    of such files. Is there a way in Perl to modify just the first 'n' lines of the file
    without having to process rest of the file as it involves a lot of IO and time.
    It depends. If the modifications don't change the length of the file
    then you can do it. If the modifications increase or decrease the
    length of the file then you have to process the entire file.


    John
    --
    use Perl;
    program
    fulfillment

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org

    __________________________________________________
    Do you Yahoo!?
    Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
    http://mailplus.yahoo.com
  • John W. Krahn at Feb 7, 2003 at 12:18 am

    Sashidhar wrote:

    --- "John W. Krahn" wrote:
    Sashidhar wrote:
    I am dealing with text files of sizes > 2 GB. I have to modify just the top 2
    lines of such files. Is there a way in Perl to modify just the first 'n' lines
    of the file without having to process rest of the file as it involves a lot of
    IO and time.
    It depends. If the modifications don't change the length of the file
    then you can do it. If the modifications increase or decrease the
    length of the file then you have to process the entire file.
    I may have to change the length of the files. Is there no way, like manipulating the
    inode entries to reflect any changes in the length. Ofcourse, I realize that this is
    specific to the linux/unix env.
    The inode entry does not affect the actual data in the file. If the
    length of the file has to be changed then the entire file has to be
    processed irregardless of which operating system (AFAIK) you are running
    this on.


    John
    --
    use Perl;
    program
    fulfillment
  • Rob Dixon at Feb 7, 2003 at 12:06 pm

    Sashidhar wrote:
    I may have to change the length of the files. Is there no way, like
    manipulating the inode entries to reflect any changes in the length.
    Ofcourse, I realize that this is specific to the linux/unix env.
    The problem is a limitation of the filing system itself. The starting
    position of a file is recorded as the number of the allocation unit
    (block) where the first byte of the file is stored on the disk; there
    is no offset to say that a file starts part-way through that block.

    If you need to change a file at its start, you therefore have to end
    up with the new data also starting at a block boundary. This is
    possible if the change in size is an exact multiple of the block size
    for your medium, in particular if the file ends up being exactly the
    same size when you can simply rewrite the first few blocks of the
    file and leave the allocation information unchanged. If the file
    is to be shortened by, say, exactly 4K bytes (or the medium's
    block size) then one or more blocks can be dropped from
    the file's allocation, but particularly for text files this happy
    coincidence is very unlikely, and so the entirety of the data
    must be rewritten to start on a block boundary.

    HTH,

    Rob

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 6, '03 at 10:12p
activeFeb 7, '03 at 12:06p
posts5
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase