Q: For the argument of the question, say today is 26/03/15. How can I 'accumulate' data for the last 5 days.
But these dates are just an example. Ideally I would like to be able to accumulate data for the last x days, once accumulated I will email accumulated information off. I will do this process once every z weeks via crontabs aid.
This is the code:
awk_variables=`echo "$line" | awk -F, '( $13 == "*OUT*" )||( $13 == "*IN*" ){print $1,$5,$10,$12,$13}' my_file.csv > /directory/some_directory/non_sorted_filtered.csv`
cat /directory/some_directory/non_sorted_filtered.csv | while read line
do
awk_variables="$line"
awk_variables_array=($awk_variables)
awk_time=${awk_variables_array[0]}
awk_container_ID=${awk_variables_array[1]}
awk_scan_count=${awk_variables_array[2]}
awk_part_number=${awk_variables_array[3]}
awk_direction==${awk_variables_array[4]}
awk_part_number_edited="${awk_part_number:3}"
awk_direction_edited="${awk_direction:1}"
awk_date=@''$awk_time
date=`date -d $awk_date +"%d/%m/%Y"`
echo -e "Date:$date Scan No:$awk_scan_count Part No:$awk_part_number_edited Direction:$awk_direction_edited"
done
This is the output:
Date:19/03/2015 Scan No:12 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:13 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:14 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:17 Part No:XXXX1234567 Direction:*OUT*
Date:19/03/2015 Scan No:18 Part No:WTTO275 Direction:*OUT*
Date:19/03/2015 Scan No:19 Part No:WTTO275 Direction:*OUT*
Date:19/03/2015 Scan No:20 Part No:WTTO275 Direction:*OUT*
Date:20/03/2015 Scan No:22 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:23 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:24 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:25 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:26 Part No:XXXX1234567 Direction:*OUT*
Date:24/03/2015 Scan No:37 Part No:WTTO523 Direction:*OUT*
Date:25/03/2015 Scan No:43 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:44 Part No:SP-TMX6BP Direction:*OUT*
Date:25/03/2015 Scan No:45 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:49 Part No:02102 Direction:*OUT*
Date:25/03/2015 Scan No:50 Part No:02103 Direction:*OUT*
Date:25/03/2015 Scan No:51 Part No:02118 Direction:*OUT*
Date:25/03/2015 Scan No:52 Part No:02132 Direction:*OUT*
Date:25/03/2015 Scan No:53 Part No:02133 Direction:*OUT*
Date:25/03/2015 Scan No:54 Part No:02134 Direction:*OUT*
Date:25/03/2015 Scan No:55 Part No:02135 Direction:*OUT*
Date:25/03/2015 Scan No:56 Part No:19178 Direction:*OUT*
Date:25/03/2015 Scan No:57 Part No:19179 Direction:*OUT*
So I would like to send the follwoing data:
Date:20/03/2015 Scan No:22 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:23 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:24 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:25 Part No:XXXX1234567 Direction:*OUT*
Date:20/03/2015 Scan No:26 Part No:XXXX1234567 Direction:*OUT*
Date:24/03/2015 Scan No:37 Part No:WTTO523 Direction:*OUT*
Date:25/03/2015 Scan No:43 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:44 Part No:SP-TMX6BP Direction:*OUT*
Date:25/03/2015 Scan No:45 Part No:WTTO548 Direction:*OUT*
Date:25/03/2015 Scan No:49 Part No:02102 Direction:*OUT*
Date:25/03/2015 Scan No:50 Part No:02103 Direction:*OUT*
Date:25/03/2015 Scan No:51 Part No:02118 Direction:*OUT*
Date:25/03/2015 Scan No:52 Part No:02132 Direction:*OUT*
Date:25/03/2015 Scan No:53 Part No:02133 Direction:*OUT*
Date:25/03/2015 Scan No:54 Part No:02134 Direction:*OUT*
Date:25/03/2015 Scan No:55 Part No:02135 Direction:*OUT*
Date:25/03/2015 Scan No:56 Part No:19178 Direction:*OUT*
Date:25/03/2015 Scan No:57 Part No:19179 Direction:*OUT*
NB: the number of scans/day will vary. Somedays it might be 100 (for example) some days it will be 0.
awk
to process your csv file, you're using thatcat squeeze | while read wise
which is prolly a hundred times slower (and error prone) + a whole block of assignments and substitutions just to format some fields... Here, play with this and try to figure out what it does:echo "1426815663,12,H08W2345678,*OUT**" | awk -F, '{print "Date:"strftime("%d/%m/%y",$1),"Scan No:"$2,"Part No:"substr($3, 4),"Direction:"substr($4, 1, length($4)-1)}' OFS='\t'
prevdays=$(date -d'5 days ago' +"Date:%d/%m/%Y")
so the stuff you need is from the first line that matches^$prevdays
up to the last line.