#!/bin/sh
if [ $# -lt 2 -o $# -gt 3 ]; then
	echo "usage: "`basename $0`" file pattern [format result as date]"
	exit 1
fi
if [ -s $1 ]; then
	if [ $# = 2 ]; then
		grep figures $1 | awk -F$2 '{print $1}' | \
		awk -F'"' '{print $(NF-8)}'
	else
		SEC=`grep figures $1 | awk -F$2 '{print $1}' | \
		awk -F'"' '{print $(NF-8)}'`
		if [ `echo $SEC | awk '{printf ("%i",$1)}'` -gt 0 ]; then
			date -d @$SEC +%d.%m.%Y
		else
			echo "n.a.perpetual"
		fi
	fi
else
	echo $1 "does not exist."
fi
