On 17 Feb 12:51, Richard Parsons wrote:
Hi everyone
I have some data like this:
something:01/01/1980:something something-else:12/05/1993:foobar another-something:32/01/2012:barfoo etc
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.