Hello monks, I have a problem with data i am trying to retrieve from a text file.

The contents of files looks like below with the data i require in a table.
The text before and after the table is just general information but varies from file to file that i read, there can be other tables after the one i am tring to read but this must be ignored.
I feel the only way to get this data is to search for words 'Bus Timetable' as this not repeated any where else in the files. But to get the data i require, i need to look at the forth line from 'Bus Timetable'. I then need to some how get the FROM DEPT TO & ARR in the order they are in table, in the following way- FROMDEPT:TOARR ( i.e. twn0900:apt0911 ). I think to stop retrieving the data it can stop when it sees the next + as this is on the last line of the table.

---TEXT BEFORE--- +---------------+ | Bus Timetable | +---------------+----+------------+-----------+------+ | BUS SERVICE DAY tm | FROM DEPT | TO ARR | 24/7 | +--------------------+------------+-----------+------+ | C4 metro mon 15 | twn 0900 | Apt 1011 | yes | | C6 intl mon 45 | LDN 1000 | XTR 1426 | no | | B2 susx mon 20 | cly 1034 | btn 1118 | no | | A0 xxxxx xxx xx | xxx xxxx | xxx xxxx | xxx | +--------------------+------------+-----------+------+ ---TEXT AFTER---

I have noticed that the file produced can continue the table on the next page but puts the name of table and the headings for the columns as before. So i would like the program to read all tables with 'Bus Timetable' heading but ignore any other tables and text.

So far i have not written any code as i am not sure how to do this as i have been learning perl only 4 weeks now. I think i understand what i want the code to do and that it is possible to do what i have asked. I know how to search for a word but i dont not know how to look a number of lines from the result of search and to look at the table. I guess it should count the number of '|' and get data between the 2 and 4 one?

If any one can help me i will be very thankful

Thank you all so much, Kwun Chang.


In reply to read text table by Anonymous Monk

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.