[ALUG] Sort dd/mm/yyyy
iDunno at sommitrealweird.co.uk
Thu Feb 17 13:30:53 GMT 2011
On 17 Feb 12:51, Richard Parsons wrote:
> Hi everyone
> I have some data like this:
> In other words, it's a colon delimited file in which the second field is a date in the form dd/mm/yyyy.
> How do I sort the whole file in date order by the second field? I can see that 'sort -k' allows me to pick the positional part of the fields and -t allows me to pick the delimiter. But I can't work out how to combine them so that the whole file is sorted.
sed -e 's#:\([0-9][0-9]\)/\([0-9][0-9]\)/\([0-9][0-9][0-9][0-9]\):#:\3-\2-\1:#'file | sort -d ":" -k 2
Should work. Note that's entirely untested and may eat your cat though.
Brett Parker http://www.sommitrealweird.co.uk/
PGP Fingerprint 1A9E C066 EDEE 6746 36CB BD7F 479E C24F 95C7 1D61
More information about the main