The Wanderer <[EMAIL PROTECTED]> writes: > I have a text file whose lines each contain two dates, of the format > "MM-DD-YYYY". I want to sort these lines into order from oldest to most > recent - that is, first by YYYY, then by MM, then by DD. After I parse > out the spaces using sed, the only whitespace remaining in the file is > the blocks of contiguous tabs which I use to divide the columns which > contain the actual data; the date I want to sort on is in the fifth such > column, which should at that point be field number 5. > > I would expect that 'sort -k 5.7,5 -k 5,5' would sort first by the > seventh character in the fifth field (the first digit of the year), thus > putting the file in order by year, and then by the entirety of the fifth > field, thus putting the file in order by month and day. It does not.
This is because the whitespace between the fields belongs to the following field, ie. the field boundary is the point between a non-whitespace and a whitespace character. Thus you either have to increase the offset by the number of whitespace characters at the start of the field (if it is consistent), or use the b flag to skip whitespace altogether. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." _______________________________________________ Bug-coreutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-coreutils
