Skip to content
Snippets Groups Projects
Commit 79eb8cb7 authored by am0ebe's avatar am0ebe
Browse files

getDates.sh: fix bug resulting from different headers. Add function to calc...

getDates.sh: fix bug resulting from different headers. Add function to calc header size for each file. Output errors/warnings to stderr
parent 6e19aa1a
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# # # #
# Determine time of last and first Trackevent in file/unit
# Determine start and end of Trackevents in files/units
# >> summarizes for all files for a unit and for all units
#
# Why? Because timestamp is not human-readable and one unit can have multiple files.
#
##
function isNumber(){
function isNumber() {
re='^[0-9]+$'
if [[ "$1" =~ $re ]]; then
return 1
......@@ -15,16 +16,30 @@ function isNumber(){
fi
}
function getHeaderSize {
HEADER_SIZE=0
while read -r line; do
if [ ${line::1} != '#' ]; then
break
fi
((HEADER_SIZE++))
done < "$1"
}
function getDates() {
# gets second/last line timestamp and transform it to date
# gets first line after header and last line timestamp and transform it to date
# for more files, will get latest/earliest date of all files
date1=`date +%s`
date2=0
for file in "$@"; do
timestamp1=`head -2 "$file" | tail -1 | cut -d';' -f1`
# echo "process file $file"
getHeaderSize "$file"
timestamp1=`head -$((HEADER_SIZE+1)) "$file" | tail -1 | cut -d';' -f1`
timestamp2=`tail -1 "$file" | cut -d';' -f1`
isNumber "$timestamp1"
if [ "$?" != 0 ]; then
if [ ${timestamp1} -lt ${date1} ]; then
......@@ -32,7 +47,7 @@ function getDates() {
file1="$file"
fi
else
echo "nonum"
echo "nonum" >> /dev/stderr
fi
isNumber "$timestamp2"
......@@ -42,7 +57,7 @@ function getDates() {
file2="$file"
fi
else
echo "nonum"
echo "nonum" >> /dev/stderr
fi
done
......@@ -63,6 +78,7 @@ function getDates() {
}
function getDatesUnit(){
for i in "$@"; do
echo "unit $i"
files=`ls "$dir"/*unit-$i-* 2> /dev/null`
......@@ -76,13 +92,12 @@ function getDatesUnit(){
}
function getDatesAll() {
earliest=`date +%s`
latest=0
getDatesUnit {1..13}
earliest=`date -d @"$earliest" +"%Y-%m-%d %T"`
latest=`date -d @"$latest" +"%Y-%m-%d %T"`
echo "unit all"
......@@ -90,6 +105,8 @@ function getDatesAll() {
echo "${latest} ${latestFile}"
}
####################################
if [ -z $1 ];then
dir="."
else
......@@ -100,4 +117,4 @@ else
fi
fi
getDatesAll # > "${dir}/../02-inspect/dates"
getDatesAll
#!/bin/bash
# scriptdir=`dirname $0`
this=`basename $0`
out1="tags_unknown"
out2="tags_info"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment