[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Apparently irrational behaviour in sort
From: |
Andreas Schwab |
Subject: |
Re: Apparently irrational behaviour in sort |
Date: |
Sun, 04 Dec 2005 11:52:16 +0100 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux) |
The Wanderer <address@hidden> 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, address@hidden
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."
- Apparently irrational behaviour in sort, The Wanderer, 2005/12/04
- Re: Apparently irrational behaviour in sort,
Andreas Schwab <=
- Re: Apparently irrational behaviour in sort, The Wanderer, 2005/12/04
- Re: Apparently irrational behaviour in sort, Eric Blake, 2005/12/05
- Re: Apparently irrational behaviour in sort, The Wanderer, 2005/12/05
- Re: Apparently irrational behaviour in sort, Brian Dessent, 2005/12/05
- Re: Apparently irrational behaviour in sort, The Wanderer, 2005/12/05
- Re: Apparently irrational behaviour in sort, Brian Dessent, 2005/12/06
- mailing list procmail rules (Re: Apparently irrational behaviour in sort), Bob Proulx, 2005/12/07