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_debian.sh (1732B)


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