[SlugBug] Re: data formatting query
Craig Andrews
craig at simplyspiffing.com
Thu Dec 8 21:21:38 GMT 2005
On Thu, Dec 08, 2005 at 09:06:02PM +0000, Bill Best wrote:
> > awk '{ print $1, $2 }' < inputfile | grep -v '^$' | sort | uniq
>
> >By the way, I'm assuming the dates in the file are all in the same month?
> >If not, then a simple sort won't work - the format ddmmyy isn't ASCII
> >sortable: 010705 (1 July '05) will be placed above 310505 (31 May 05). The
> >date formay 'yymmdd' or even beter 'yyyymmdd' allows simple ASCII sorts of
> >dates without having to resort to convoluted or custom sort rules/routines.
>
> you've anticipated my next question...
>
> any quack-ish way to get the output into date order?
Stick this in-between the grep and the sort:
perl -pe 's/(\d{2})(\d{2})(\d{2})/$3$2$1/'
The total command would be:
awk '{ print $1, $2 }' < inputfile | grep -v '^$' |\
perl -pe 's/(\d{2})(\d{2})(\d{2})/$3$2$1/' | sort | uniq
That should do the trick :)
--
Craig Andrews <craig at simplyspiffing.com>
More information about the SlugBug
mailing list