On 2012-08-06 Jobst Schmalenbach trolled:
> Dear I say it ... Excel does a good job at this.
> Export as csv, import into Excel, select the column and sort.
That won't give the result you want, due the varying number of columns
in each record. If you fix that then the sort command can trivially sort
the file anyway.
On 2012-08-03 lists asked:
> how could I date order sort on penultimate string to end up with date
> ordered ?
>
> Job 1978924 (8) Ttt Pp 20-11-2012 Notes
> Job 1923886 Ccc Pl 31-08-2012 Notes
Unix is a set of tools which you string together. So let's extract the
sort field and and "decorate" the start of the line with its sort field:
awk '{ printf "%s %s\n", $(NF-1), $0 }'
and then sort by it
sort -t '-' -k 3n -k 2n -k 1n
and finally undecorate the sort key we added
cut -f 2- -d ' '
For example, if the file is fred.txt (all the following is one line, the
wraps are added by my mailer):
awk '{ printf "%s %s\n", $(NF-1), $0 }' fred.txt | sort -t '-' -k 3n -k
2n -k 1n | cut -f 2- -d ' '
This technique is well known and is documented in the usage examples in
the 'sort' info page.
-glen
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html