Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

INPUT:

b|2013.06.03. 18:47|
a|2013.06.03. 13:15|
c|2013.06.03. 13:53|

needed OUTPUT:

a|2013.06.03. 13:15|
c|2013.06.03. 13:53|
b|2013.06.03. 18:47|

How can I sort the dates correctly in ascendant order? The delimiter is the |.

P.S.

sort -t "|" -n -k 2

is not enough, because it doesn't put the HH:MM in good order, only the YYYY.MM.DD.

share|improve this question
up vote 3 down vote accepted

Try:

sort -t "|"  -k 2

By leaving out the -n, you sort on the whole string between '|' characters not just the first number that can be made out of that string (2013).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.