Reputation: 1
I am a beginner in scripting and I am trying to set TPS value for a system according to the time of the server when it executes the script. I am having csv file which contains start time , End time and TPS columns which starts from 00:00 to 23:59 as follows.
StartTime,EndTime,TPS
.....,.....,...
.....,.....,...
11:30,12:00,100
12:00,12:45,200
12:45,13:30,520
.....,.....,...
.....,.....,...
23:40,23:50,920
23:50,23:59,250
Time gaps are not uniform. if the server current time is 11:35, I want to chose the "11:30,12:00,100" line and get it into a seperate file (since 11:35 lies between 11:30-12:00). Also the chosen line will be deleted from the initial csv file.
#Current time into a variable
TS=$(date | cut -d ' ' -f4 | cut -d ':' -f1,2)
echo "Current time = $TS"
Writing the relevant line to a seperate file and removing that line from the initial file is fine for me.
if the TS=11:35, I want to get the output as "11:30,12:00,100" from that csv file. Struggling to code how to get that matching line.
Upvotes: -2
Views: 88
Reputation: 1707
Partial answer:
Your "datalist" seem improperly conceived for full coverage. You have gaps of 1 minute at each interval which is not being captured.
To get proper coverage of all activity, you need to have first time period ending with ${EndTime_1} ... and ... the next time period starting with ${StrtTime_2}=${EndTime_1}.
When scanning, you should specify range as
if [ "${StrtTime_x}" -le "${LineTime}" -a "${LineTime}" -lt "${EndTime_x}" ]
then
...{action}...
fi
Note: the first comparison is -le , but the second is only -lt , thereby ensuring lines never match both conditions.
Upvotes: 1