46 строки
1.1 KiB
Plaintext
46 строки
1.1 KiB
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
#####################################################################
|
||
|
# 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
|
||
|
}
|
||
|
|
||
|
if [ -z "$1" ]; then
|
||
|
echo "Need the name of a timing file"
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
thefile=$1
|
||
|
sed '/^$/d' $thefile > ${thefile}_tmp
|
||
|
sort ${thefile}_tmp > ${thefile}
|
||
|
|
||
|
read line < ${thefile}
|
||
|
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
|
||
|
done < ${thefile} > ${thefile}_tmp
|
||
|
|
||
|
cat ${thefile}_tmp > ${thefile}
|
||
|
|
||
|
rm -f ${thefile}_tmp
|