2014-09-15 22:00:46 +04:00
|
|
|
#!/bin/bash
|
2014-09-23 16:59:54 +04:00
|
|
|
#
|
|
|
|
# Copyright (c) 2014 Artem Polyakov <artpol84@gmail.com>
|
|
|
|
# $COPYRIGHT$
|
|
|
|
#
|
|
|
|
# Additional copyrights may follow
|
|
|
|
#
|
|
|
|
# $HEADER$
|
2014-09-15 22:00:46 +04:00
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Evaluate a floating point number expression.
|
|
|
|
|
|
|
|
function float_eval(){
|
|
|
|
float_scale=9
|
|
|
|
local stat=0
|
|
|
|
local result=0.0
|
|
|
|
if [[ $# -gt 0 ]]; then
|
|
|
|
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
|
|
|
|
stat=$?
|
|
|
|
if [[ $stat -eq 0 && -z "$result" ]]; then
|
|
|
|
stat=1;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo $result
|
|
|
|
return $stat
|
|
|
|
}
|
|
|
|
|
2014-09-23 16:59:54 +04:00
|
|
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
|
|
|
echo "Need the name of a timing file and the output file"
|
2014-09-15 22:00:46 +04:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
thefile=$1
|
2014-09-23 16:59:54 +04:00
|
|
|
postfile=$2
|
2014-09-15 22:00:46 +04:00
|
|
|
sed '/^$/d' $thefile > ${thefile}_tmp
|
2014-09-23 16:59:54 +04:00
|
|
|
sort ${thefile}_tmp > ${postfile}
|
2014-09-15 22:00:46 +04:00
|
|
|
|
2014-09-23 16:59:54 +04:00
|
|
|
read line < ${postfile}
|
2014-09-15 22:00:46 +04:00
|
|
|
first_ts=`echo $line | awk '{ print $1 }' | sed -e 's/s//'`
|
|
|
|
prev_ts=$first_ts
|
|
|
|
echo $first_ts
|
|
|
|
|
|
|
|
while read line ; do
|
|
|
|
cur_ts=`echo $line | awk '{ print $1 }' | sed -e 's/s//'`
|
|
|
|
dif1=`float_eval "$cur_ts - $first_ts"`
|
|
|
|
dif2=`float_eval "$cur_ts - $prev_ts"`
|
|
|
|
newline=`echo $line | sed -e "s/$cur_ts/$dif1:$dif2/"`
|
|
|
|
prev_ts=$cur_ts
|
|
|
|
echo $newline
|
2014-09-23 16:59:54 +04:00
|
|
|
done < ${postfile} > ${thefile}_tmp
|
2014-09-15 22:00:46 +04:00
|
|
|
|
2014-09-23 16:59:54 +04:00
|
|
|
cat ${thefile}_tmp > ${postfile}
|
2014-09-15 22:00:46 +04:00
|
|
|
|
2014-09-23 16:59:54 +04:00
|
|
|
rm -f ${thefile}_tmp
|