Hello. I have a text file

Ok, you have a series of text characters that periodically have a "\n" in the data stream.

The disk and the file system hides some "ugliness" from you, but basically you can think of a disk file as a stream of bytes from 0 to N.

A "line" has some number of characters followed by "\n". There is no general way to "jump over 5 lines" because the number of characters contained within those lines is variable and unknown. You have to read sequentially through the bytes and count the number of "\n" chars to decide that you've skipped over say 5 lines.

There are some types of disk data structures that have fixed length records and in that case, it is possible to calculate "the starting byte address" of record 213 and you can "seek" (or in other words "jump") there.

The disk system reads sequential characters very quickly. Even a couple of thousand characters of "header" is normally of no consequence.

Now if you have say 1MB of stuff to "plow through" at the beginning, then maybe you have the wrong data structure?

But it appears to me that you just need to "read and throw away" the lines that don't matter until you get to the "real stuff".


In reply to Re: Reading lines from a specific location in a text file. by Marshall
in thread Reading lines from a specific location in a text file. by peokai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.