I have a file with contents like below;
864440 17:59:48.143
864440 17:59:48.221
864441 17:59:48.159
864441 17:59:48.221
864442 17:59:48.159
864442 17:59:48.237
864443 17:59:48.174
864444 17:59:48.190
864444 17:59:48.253
864445 17:59:48.206
864445 17:59:48.268
864446 17:59:48.221
864446 17:59:48.284
I am doing a while loop to read the 1st and 2nd value and put it on a variable like below;
while read list; do
jbnum=`echo $list|awk '{print $1}'`
time=`echo $list|awk '{print $2}'`
done < jobstmp.txt
I would like to add an if condition that if the jbnum is equal to the next iteration it would get the time difference of the same job number if not then do nothing and go to next iteration
Thanks for all those who answered the solution below based on the code provided by Chris Maes
while read jobnum time
do
if [[ "$prevjobnum" == "$jobnum" ]]
then
ENDTIME=`date +%s.%N -d "$time"`
STARTTIME=`date +%s.%N -d "$prevtime"`
DIFF=$(echo $ENDTIME - $STARTTIME | bc | sed 's/0\{1,\}$//')
echo "$prevjobnum time is $DIFF seconds"
fi
# keep variables for next iteration
prevjobnum=$jobnum
prevtime=$time
done < jobstmp.txt