Suppose there was a meeting and the meeting record is saved in a CSV file. How to write a bash script/awk script to find out the total amount of time for which an employee stayed online. One employee may leave and rejoin the meeting, all his/her online time should be calculated.
What I did is as follows, but got stuck on how to compare one record with all other record, and add the total time of each joined and left pairs of a person.
#!/bin/bash
inputFile=$1
startTime=$(date -u -d $2 +"%s")
endTime=$(date -u -d $3 +"%s")
awk 'BEGIN{ FS=","; totalTime=0; }
{
for (rows=1; rows <= NR; rows++) {
#I am stuck here on how to compare a record with each and every record
if (($1==?? && $2=="Joined") && ($1==?? && $2=="Left")) {
totalTime=$($(date -u -d $3 +"%s")-$(date -u -d $3 +"%s"))
print $1 "," $totalTime +"%H:%M:%S"
}' $inputFile
The start_time and end_time of the meeting are given at command line such as:
$ ./script.sh input.csv 10:00:00 13:00:00
The output look like this: (Can be stored in an output file)
Bob, 00:30:00
John, 01:02:00
The contents of the CSV file is as follows:
Employee_name, Joined/Left, Time
John, joined, 10:00:00
Bob, joined, 10:01:00
James, joined, 10:00:30
Bob, left, 10:20:00
Bob, joined, 10:35:00
Bob, left, 11:40:00
James, left, 11:40:00
John, left, 10:41:00
Bob, joined, 11:45:00