script pour établir une bdd Ãà partir d'un tsv avec différent format - retour accueil
git clone git://bebou.netlib.re/laradb
Log | Files | Refs |
commit 5335bdd328d94344dcb391589b7b7122cacf3709 parent 1bc1280be03a683174e906eb0d88a83f12f9154a Auteurice: vi <vi@bb.re> Date: Sat, 2 Nov 2024 17:56:55 +0100 date_epoch script done but prototype -ish Diffstat:
M | src/utils/date_epoch.sh | | | 39 | +++++++++++++++++++++++++++++++++++---- |
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/src/utils/date_epoch.sh b/src/utils/date_epoch.sh @@ -1,13 +1,44 @@ #! /bin/sh +# what this script does : +# - cleaning the date date so it is under the unix epoch format so that +# - it can be used as a value for bc in src/frise.sh # @TODO: apply to both field, and use tsv utils rather than cut to use field header names instead of -f4,5 if -# one day the start_date and end_date aren't anymore the 4th and 5th field of the tsv (however header names must stay persistent -cut -f4 -d" " src/db.tsv | +# if one day the start_date and end_date aren't anymore the 4th and 5th field of the tsv (however header names must stay persistent +# NaN values are defaulted to 1900 01 01 00:00 + + +#start= `mktemp tmp/start.XXXXXXX` +#end= `mktemp tmp/end.XXXXXXX ` +# | xargs date -j +%s # to transform every value into seconds since epoch to bc for the frise + +clean(){ +cut -f$1 -d" " src/db.tsv | sed '1d; s/-//g; # date 19701210 s/^\([0-9]*\)\(.*$\)/\1 #\2/g; # prepare for cleaning with comment s/^\(.{2}\).*/\1/; # finale clean 1970 #comment s/^\([0-9]*\)/\100000000/; #adding the zero we need for the date xargs command to work +# second part data cleaning for xargs date s/[0-9]/X/13; #preparation to delete the non-needed zero -s/X.[^#]*/ /gw dist/date_epoch.tsv' #delete the zero and write file to a tsv +s/X.[^#]*/ /g; #delete the zero +s/^\([12]...\)0000/\10101/; # 197001010000 @TODO for date after 2000** +s/^\([12].....\)00/\101/; # 197009010000 +s/#/ #/; # make the comments a new field #| once there was a pipe +s/^0\{8\}/190001010000/; # for NaN gives a date' +#cut -f1 | +#xargs -n1 date -j +%s +} +clean 4 > tmp/start +clean 5 > tmp/end +paste -d "\t" tmp/start tmp/end | tee tmp/dateEpoch_final.tsv + + +cut -f1 tmp/start | +xargs -n1 date -j +%s | tee tmp/start_unixepoch + + +cut -f1 tmp/end | +xargs -n1 date -j +%s > tmp/end_unixepoch +paste -d "\t" tmp/start_unixepoch tmp/end_unixepoch | tee tmp/dateEpoch_final.tsv + -# | xargs date -j +%s # to transform every value into seconds since epoch to bc for the frise