From 79eb8cb7122659086b50e3f41ec1c0e51c51c59c Mon Sep 17 00:00:00 2001 From: am0ebe <am0ebe@gmx.de> Date: Fri, 11 Jun 2021 11:32:39 +0200 Subject: [PATCH] getDates.sh: fix bug resulting from different headers. Add function to calc header size for each file. Output errors/warnings to stderr --- getDates.sh | 39 ++++++++++++++++++++++++++++----------- unknown-tags.sh | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/getDates.sh b/getDates.sh index 5642fee..e769dbb 100755 --- a/getDates.sh +++ b/getDates.sh @@ -1,12 +1,13 @@ #!/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 diff --git a/unknown-tags.sh b/unknown-tags.sh index c1fb02b..f8da8b5 100755 --- a/unknown-tags.sh +++ b/unknown-tags.sh @@ -1,5 +1,5 @@ #!/bin/bash -# scriptdir=`dirname $0` + this=`basename $0` out1="tags_unknown" out2="tags_info" -- GitLab