-2

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.

4
  • Question is not really clear for me. What's TPS? What's the expected output of the snippet?
    – LMC
    Commented Oct 27, 2022 at 21:59
  • SO isn't a code writing service; you're expected to show your (coding) effort, the (wrong) output generated by your code and the (correct) expected output, making sure both sets of output correspond to the provided sample input
    – markp-fuso
    Commented Oct 27, 2022 at 22:02
  • TPS means Transactions per second. Just ignore it. I want to get a matching range from the csv file to a given specific time ( server time "$date"). That's only .
    – d_rulz
    Commented Oct 27, 2022 at 22:05
  • please confirm that if the current time is 12:00 then you want to print both lines 11:30,12:00,100 and 12:00,12:45,200 as well as remove both lines (from the csv)
    – markp-fuso
    Commented Oct 28, 2022 at 15:08

1 Answer 1

1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.