Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Fellow monks

I am building an application that should read and collect data from many NetApp filers and store them in a database for making periodical usage reports. To avoid bothering production filers during the early stage of development I created a file for each filer containing the output of the quota report command.

The output looks like:

K-Bytes Files Type ID Volume Tree Used Limit Used Limit Quo +ta Specifier ----- -------- -------- -------- -------- -------- ------- ------- --- +------------ tree 7 data pre_appltop 3449512 4194304 30723 +- /vol/data/pre_appltop tree 6 data pre_appsdata 23327540 31457280 142938 + - /vol/data/pre_appsdata

To simulate the command output, I'd need to read the file line by line, print if it doesn't begin with tree, otherwise substitute the fifth field (say: $field[4] with int rand $field[4]). Since the dashed line on top of the report gave me an hint for creating a sprintf format, I found that this one-liner just does the job I need:

perl -pe 'next unless /^tree/ ; @f=split ; $f[4] = int rand $f[4] ; $_ = sprintf "%-5s %8d %-8s %-8s %8d %8d %7d %7d %-15s\n",@f'

But what if I hadn't any hint? How would you replace the fourth field leaving the line formatting in a sane state?

Thanks in advance for your suggestions


In theory, there is no difference between theory and practice. In practice, there is.

In reply to changing a portion of a line leaving its formatting intact by bronto

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2020-10-28 01:12 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (259 votes). Check out past polls.