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.
|