
#!/bin/sh
if [ $# -lt 1 -o $# -gt 2 ]; then
	echo "usage: "`basename $0` "file [nextyear]"
	exit 1
fi
if [ -e $1 ]; then
	if [ $# = 1 ]; then
		grep "`date +%Y` " $1 | grep -v `date +%d.%m.%Y` >> $1.tmp
	else
		grep "`date -d 1year +%Y` " $1 >> $1.tmp
	fi
	for a in `awk '{print $1}' $1.tmp`
	do
		grep $a $1.tmp | awk '{print $1,$2}'| awk -F"." \
		'{print $1,$2,$3}' >> $1.date
		grep $a $1.tmp | awk '{ORS=" "; print $1; for \
		(i=3;i<=NF;i++) print $i; ORS="\n"; print ""}' >> $1.txt
	done
	sort -k 3,4 $1.date > $1.tmp
	for a in `awk '{print $1}' $1.tmp`
	do
		grep $a $1.tmp | awk '{ORS=" "; print $1,$2"."$3"."$4}' \
		>> $1.out
		grep $a $1.txt | awk '{ORS=" "; for (i=2;i<=NF;i++) print $i; \
		ORS="\n"; print ""}' >> $1.out
	done
	cat $1.out
	rm $1.*
else
	echo $1 "does not exist."
fi
