laradb

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 |

date_epoch.sh (2301B)


      1 #! /bin/sh
      2 
      3 # what this script does : 
      4 # - cleaning the date date so it is under the unix epoch format so that
      5 # - it can be used as a value for bc in src/frise.sh 
      6 
      7 # @TODO: apply to both field, and use tsv utils rather than cut to use field header names instead of -f4,5 if
      8 # 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 
      9 # NaN values are defaulted to 1900 01 01 00:00 
     10 
     11 #start= `mktemp tmp/start.XXXXXXX`  
     12 #end= `mktemp tmp/end.XXXXXXX `  
     13 # | xargs date -j +%s # to transform every value into seconds since epoch to bc for the frise 
     14 
     15 clean(){
     16 cut -f$1 -d"	" src/db.tsv | 
     17 sed '1d;
     18 s/-//g; # date 19701210
     19 s/^\([0-9]*\)\(.*$\)/\1 #\2/g; # prepare for cleaning with comment
     20 s/^\(.{2}\).*/\1/; # finale clean 1970 #comment
     21 s/^\([0-9]*\)/\100000000/; #adding the zero we need for the date xargs command to work
     22 # second part data cleaning for xargs date
     23 s/[0-9]/X/13; #preparation to delete the non-needed zero
     24 s/X.[^#]*/ /g;   #delete the zero
     25 s/^\([12]...\)0000/\10101/; # 197001010000 @TODO for date after 2000**
     26 s/^\([12].....\)00/\101/; # 197009010000
     27 s/#/	#/; # make the comments a new field #| once there was a pipe
     28 s/^0\{8\}/190001010000/; # for NaN gives a date
     29 # for debian date add :
     30 s/0000 / /; # in format YYYYMMDD '
     31 #cut -f1 | 
     32 #xargs -n1 date -j +%s 
     33 }
     34 clean 5 > tmp/start 
     35 clean 6 > tmp/end 
     36 paste -d "\t" tmp/start tmp/end 
     37 
     38 cut -f1 tmp/start | 
     39 xargs -I XX -d'\n' -n1  date +%s --date="XX" | 
     40 tee tmp/start_unixepoch
     41 
     42 cut -f1 tmp/end | 
     43 xargs -I XX -d'\n' -n1  date +%s --date="XX" | 
     44 tee tmp/end_unixepoch
     45 
     46 paste -d "\t" tmp/start_unixepoch tmp/end_unixepoch | tee tmp/dateEpoch_final.tsv
     47 
     48 # append the epoch time to the one tsv
     49 
     50 #cat tmp/dateEpoch_final.tsv | 
     51 #sed '1s/^/start_unixepoch 	end_unixepoch @ /' |
     52 # tr '@' '\n' | tee  tmp/dateEpoch_final.tsv
     53 
     54 cp --attributes-only tmp/dateEpoch_final.tsv  tmp/dateEpoch_final.tsv.tmp  
     55 <tmp/dateEpoch_final.tsv sed '1s/^/start_unixepoch 	end_unixepoch @ /' | 
     56 tr '@' '\n' > tmp/dateEpoch_final.tsv.tmp &&
     57 mv tmp/dateEpoch_final.tsv.tmp tmp/dateEpoch_final.tsv 
     58 cat tmp/dateEpoch_final.tsv
     59 
     60 cp --attributes-only src/db.tsv tmp/db.tmp
     61 paste -d "\t" src/db.tsv tmp/dateEpoch_final.tsv > tmp/db.tmp &&
     62 mv tmp/db.tmp src/db.tsv 
     63 cut -f19- src/db.tsv
     64 
     65 
     66