The output of df is fixed length fields. You can use pack/unpack to get at the data. Read the pack tutorial on how this works. Basically, you calculate the field widths and feed them to pack which splits up the string for you. Then all your loop needs to do is recognize header and footer lines and handle them as special cases. Everything else is simply unpack()ed. No messy regexes.

Based on your data, I would do something like:

  1. read line of dashes
  2. read header line and parse with regex(unpack could work here)
  3. read lines till I saw /^Filesystem/
  4. read lines and send through unpack until a blank line
  5. process footer lines with regex or unpack
  6. read next line of dashes and back to the top

I notice that your data may be coming from different sources with different field widths. This may just be the cutting and pasting. But if it is so, you can actually use the header line of your data(from each machine) with index() to calculate the field widths and feed those to pack.

HTH


In reply to Re: couple of file content manipulation questions by pzbagel
in thread couple of file content manipulation questions by vxp

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.