My script (in bash) aims to do this job:
gets start and stop time from a file,
file_A
. The time range usually is 3-24 hours.Based on this time window of
[start_time, stop_time]
got fromfile_A
, I need to find specific files among totally 10k log files(and will increase along with the experimental running), each of which recorded around 30 minutes. That's to say, I have to find 6-50 log files among 10k ones.After confirming the correct log files, I need to print out interesting data.
Step 1) and 3) are OK, I did it already. Right now, I'm stuck in step 2), Especially in two places:
(a). How to select appropriate files efficiently by their names since the log files named as time. Every log file named as log_201305280650
which means 2013 / May 28 / 06 :50. That's to say, according to the time get from file_A, I need to confirm the corresponding log files by their names which is a hint of time.
(b). Once the files are selected, read the items(like temperature, pressure etc) from this file whose time is inside of time window. Because each file records 30 minutes, which means some of the entry in this file can't satisfy time window.
For instance,
From step 1), My time window is set to [201305280638, 201305290308].
from step 2), I know the log file(log_201305280650) contains the start time of 201305280638. So I need to read all of temperature and pressure for the entries below 201305280638.
the log files name is log_201305280650 (= 2013 / May 28 / 06 :50)
Time temperature pressure ...
201305280628 100, 120 ...
201305280629 100, 120 ...
... ... ...
201305280638 101, 121 ...
201305280639 99, 122 ...
... ... ...
201305280649 101, 119 ...
201305280650 102, 118 ...
My fake script is following.
get time_start from /path/file_A
get time_stop from /path/file_A
for file in /path_to_log_files/*
do
case "$file" in
*)
If [[log file name within time window of (time_start, time_stop)]]; then
loop over this file to get the entry whose time is just within (time_start, time_stop)
read out temperature and pressure etc.
fi
esac
done