Com base na suposição abaixo dos dados de entrada, eu escrevi este código ..
passa o arquivo de entrada como argumento para o script
arquivo de entrada
$ cat input
2017-01-03T00:00:15.529596-03:00 session-enter TEST1
......
.......
......
2017-01-03T00:00:37.529596-03:00 session-exit TEST1
.....
.....
2017-01-03T00:00:18.529596-03:00 session-enter TEST2
......
.......
......
2017-01-03T00:03:20.529596-03:00 session-exit TEST2
...........
..........
2017-01-03T00:00:18.529596-03:00 session-enter TEST3
......
.......
......
2017-01-03T02:03:20.529596-03:00 session-exit TEST3
extract.sh
#!/bin/bash
SESSION_LOG_FILE=${1}
SESSION_EXTRACT_FILE=/tmp/$$.txt
awk '/enter/{sname=$NF;start=$1;}/exit/ && $0~sname{end=$1;}start && end{print sname,start,end;start="";end="";}' "${SESSION_LOG_FILE}" > ${SESSION_EXTRACT_FILE}
while read SESSION_NAME SESSION_START SESSION_END
do
echo "---------${SESSION_NAME}---------"
echo "Start Time : ${SESSION_START}"
echo "End Time : ${SESSION_END}"
START_EPOCH=${SESSION_START%-*}
START_EPOCH=$(date -d "${START_EPOCH}" +%s)
END_EPOCH=${SESSION_END%-*}
END_EPOCH=$(date -d "${END_EPOCH}" +%s)
DIFFERENCE=$((${END_EPOCH}-${START_EPOCH}))
echo "DIFFERENCE in seconds : ${DIFFERENCE}"
done < "${SESSION_EXTRACT_FILE}"
saída
$ ./extract.sh input
---------TEST1---------
Start Time : 2017-01-03T00:00:15.529596-03:00
End Time : 2017-01-03T00:00:37.529596-03:00
DIFFERENCE in seconds : 22
---------TEST2---------
Start Time : 2017-01-03T00:00:18.529596-03:00
End Time : 2017-01-03T00:03:20.529596-03:00
DIFFERENCE in seconds : 182
---------TEST3---------
Start Time : 2017-01-03T00:00:18.529596-03:00
End Time : 2017-01-03T02:03:20.529596-03:00
DIFFERENCE in seconds : 7382
verifique se o tempo é maior que 3600
#!/bin/bash
SESSION_LOG_FILE=${1}
SESSION_EXTRACT_FILE=/tmp/$$.txt
awk '/enter/{sname=$NF;start=$1;}/exit/ && $0~sname{end=$1;}start && end{print sname,start,end;start="";end="";}' "${SESSION_LOG_FILE}" > ${SESSION_EXTRACT_FILE}
while read SESSION_NAME SESSION_START SESSION_END
do
START_EPOCH=${SESSION_START%-*}
START_EPOCH=$(date -d "${START_EPOCH}" +%s)
END_EPOCH=${SESSION_END%-*}
END_EPOCH=$(date -d "${END_EPOCH}" +%s)
DIFFERENCE=$((${END_EPOCH}-${START_EPOCH}))
if [ "${DIFFERENCE}" -gt "3600" ]
then
echo "---------${SESSION_NAME}---------"
echo "Start Time : ${SESSION_START}"
echo "End Time : ${SESSION_END}"
echo "DIFFERENCE in seconds : ${DIFFERENCE}"
fi
done < "${SESSION_EXTRACT_FILE}"