If I understand correctly, you have a database of flat files -- that is, each text file is a single record -- and you want to periodically set a field (in this case, the second one) in each record to 0.

If that's the case, something like

cd [data directory]; for i in *.txt; do perl -pi.bak -e 's/.*/0/ if $. + == 2' $i; done

in your crontab will work. ($. is the input line number, see perlvar.) This is imperfect, though, because of the possibility that two programs might both be trying to change the same text file simultaneously, but it might be Good Enough. Better would be to lock (see flock) each file before writing to it.

Note that the general practice is to collect all records of them same type into a single file, rather than have them spread out in individual files, and have one of the fields be a unique identifier (the "primary key"). One advantage to this is that is makes searching through your database (relatively) fast and simple, since you only need to open one file.

p.s. rather than posting the same question multiple times, it's better to a) create an actual user so you can edit your posts and b) read the Site How To.


In reply to Re: making scalers back to 0.... by eg
in thread making scalers back to 0.... 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.