timeline_filter.sh0000755000175000017500000001662111037463160013255 0ustar nemonemo# !/bin/bash/ # #estrae dalla time line gli eventi avvenuti in un determinato intervallo di tempo # rifatto verifica_intervallo # controlla esistenza file controlla_path () { if ! [ -e $1 ] then echo "il file non esiste, inseriscilo nuovamente" file_check=0 else file_check=1 fi } # controlla esatezza della data, formato, esistenza mese, giorno, anche bisestile, anno compreso tra 1960 e data attuale controlla_data () { anno_corrente=$(date |awk '{print $6}') num_caratteri=$(echo -n $1 | wc -m) # echo "data di "$num_caratteri data_check=1 if [ $num_caratteri -ne 8 ] then echo "data errata" data_check=0 else giorno=$(echo ${1:0:2}) mese=$(echo ${1:2:2}) anno=$(echo ${1:4:4}) if [ $anno -lt 1960 -o $anno -gt $anno_corrente ] then echo "anno non valido" data_check=0 else if [ $mese -ge 13 ] then echo "mese non valido" data_check=0 else case $mese in 01) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; 02) controllo_bisestile $anno if [ "$bisestile" = "y" ] then if [ $giorno -gt 29 ] then echo "giorno non valido" data_check=0 fi else if [ $giorno -gt 28 ] then echo "giorno non valido" data_check=0 fi fi;; 03) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; 04) if [ $giorno -gt 30 ] then echo "giorno non valido" data_check=0 fi;; 05) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; 06) if [ $giorno -gt 30 ] then echo "giorno non valido" data_check=0 fi;; 07) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; 08) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; 09) if [ $giorno -gt 30 ] then echo "giorno non valido" data_check=0 fi;; 10) if [ $giorno -gt 30 ] then echo "giorno non valido" data_check=0 fi;; 11) if [ $giorno -gt 30 ] then echo "giorno non valido" data_check=0 fi;; 12) if [ $giorno -gt 31 ] then echo "giorno non valido" data_check=0 fi;; esac fi fi fi } # controllo se l'anno è bisestile controllo_bisestile () { resto_100=$(( $1 % 100 )) resto_4=$(( $1 % 4 )) resto_400=$(( $1 % 400 )) if [ $resto_400 -eq 0 ] then bisestile=y else if [ $resto_100 -ne 0 -a $resto_4 -eq 0 ] then bisestile=y else bisestile=n fi fi } # converte data, o meglio mese per avere il formato letterale converti_data () { giorno=$(echo ${1:0:2}) mese=$(echo ${1:2:2}) anno=$(echo ${1:4:4}) case $mese in 01) month=Jan;; 02) month=Feb;; 03) month=Mar;; 04) month=Apr;; 05) month=May;; 06) month=Jun;; 07) month=Jul;; 08) month=Aug;; 09) month=Sep;; 10) month=Oct;; 11) month=Nov;; 12) month=Dec;; esac } # converte mese in formato numerico converti_mese () { case $1 in Jan) mese1_num=01;; Feb) mese1_num=02;; Mar) mese1_num=03;; Apr) mese1_num=04;; May) mese1_num=05;; Jun) mese1_num=06;; Jul) mese1_num=07;; Aug) mese1_num=08;; Sep) mese1_num=09;; Oct) mese1_num=10;; Nov) mese1_num=11;; Dec) mese1_num=12;; esac } # controllo che l'occorenza della time-line sia interna all'intervallo di data definito dall'utente per decidere se dumparla o meno verifica_intervallo () { data_low=$lower_year$lower_month_num$lower_day data_up=$upper_year$upper_month_num$upper_day data_evento=$1$2$3 if [ $data_evento -ge $data_low -a $data_evento -le $data_up ] then check=1 else check=0 fi } # --------------MAIN--------MAIN-----------MAIN------------------------------------ out1=$(date | sed 's/ //g') out2="timeline_filter_"$out1 file_check=0 while [ "$file_check" = "0" ] do echo " " echo "inserisci il percorso del file di time line :" read path controlla_path $path done primo=$(head -n 10 $path|grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}\ [[:digit:]]\{4\}"|head -n 1) primo_1=$(echo ${primo:0:30} ) echo " " echo "la time line parte dal: "$primo_1 y=0 y1=0 while [ "$y" = "0" ] do y2=$(( $y1 + 10 )) if [ 'tail -n $y2 $path | grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}\ [[:digit:]]\{4\}" ' ] then ultimo=$(tail -n $y2 $path | grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}\ [[:digit:]]\{4\}"|tail -n 1) break fi done ultimo_1=$(echo ${ultimo:0:30} ) echo "e termina al: "$ultimo_1 echo " " intervallo_check=0 while [ "$intervallo_check" = "0" ] do data_check=0 while [ "$data_check" = "0" ] do echo "mostra gli eventi dal (ddmmyyyy) :" read lower controlla_data $lower done converti_data $lower lower_day=$giorno lower_month=$month lower_month_num=$mese lower_year=$anno lower_inverso=$anno$mese$giorno data_check=0 while [ "$data_check" = "0" ] do echo " " echo "al (ddmmyyyy) :" read upper controlla_data $upper done converti_data $upper upper_day=$giorno upper_month=$month upper_month_num=$mese upper_year=$anno upper_inverso=$anno$mese$giorno if [ $upper_inverso -eq $lower_inverso -o $upper_inverso -gt $lower_inverso ] then break else intervallo_check=0 echo "errore nell'inserimento date" echo "il limite superiore inserito è minore a quello inferiore" echo "inserisci nuovamente le date" echo " " fi done cerca=0 while [ "$cerca" = "0" ] do echo " " echo "vuoi ricercare una stringa? y/n" read risposta case $risposta in y) cerca_stringa=1 echo "inserisci la stringa (es.nome file o directory - la ricerca è case insensitive)" read stringa break;; n) cerca_stringa=0 stringa=. break;; *) "non hai risposto correttamente" cerca=0;; esac done for i in $(grep -n "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}" $path|awk -F ":" '{print $1}') do anno1=$(sed -n "$i,$i"p $path|grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}"|awk '{print $4}') mese1=$(sed -n "$i,$i"p $path|grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}"|awk '{print $2}') converti_mese $mese1 giorno1=$(sed -n "$i,$i"p $path|grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}"|awk '{print $3}') verifica_intervallo $anno1 $mese1_num $giorno1 time1=$(sed -n "$i,$i"p $path|grep "[[:alpha:]]\{3\}\ [[:alpha:]]\{3\}\ [[:digit:]]\{2\}"|awk '{print $5}') j=$i if [ "$check" = 1 ] then if [ "$cerca_stringa" = "1" ] then sed -n "$i,$i"p $path| rev | awk '{print $1 }'| rev>/tmp/01 if grep -qi "$stringa" /tmp/01 then sed -n "$i,$i"p $path >> $out2 fi j=$(( $j + 1 )) z=1 while [ "$z" != "0" ] do first=$(sed -n "$j,$j"p $path|cut -c 1) if [ "$first" = " " ] then sed -n "$j,$j"p $path| rev | awk '{print $1 }'| rev>/tmp/01 if grep -qi "$stringa" /tmp/01 then echo -n "----"$mese1 $giorno1 $anno1 $time1" ">> $out2 sed -n "$j,$j"p $path| sed 's/^ *//'>> $out2 fi j=$(( $j + 1 )) else break fi done else sed -n "$i,$i"p $path >> $out2 j=$(( $j + 1 )) z=1 while [ "$z" != "0" ] do first=$(sed -n "$j,$j"p $path|cut -c 1) if [ "$first" = " " ] then sed -n "$j,$j"p $path>> $out2 j=$(( $j + 1 )) else break fi done fi fi done if ! [ -e $out2 ] then echo "NON SONO STATE TROVATE OCCORREZZE CHE RISPONDANO ALLE RICHIESTE" else echo " " echo "**********************************************" echo "output in "$out2 echo " " fi exit