0

I've an issue, I wonder if you can help me. All I have to do is sorting these format by Hour element. But that element is in this format:

192.168.100.200 - unauthenticated 25/Sep/2015:18:52:18 -0500 
192.168.100.200 - unauthenticated 29/Sep/2015:14:20:41 -0500 
192.168.100.200 - unauthenticated 29/Sep/2015:14:43:16 -0500 

192.168.100.200 - unauthenticated 29/Sep/2015:14:44:04 -0500 
192.168.100.200 - unauthenticated 29/Sep/2015:15:30:50 -0500 
192.168.100.200 - unauthenticated 30/Sep/2015:13:53:04 -0500 
192.168.100.200 - unauthenticated 30/Sep/2015:14:07:48 -0500 

I've to sort by the field 14:07:48 I already read I can sort it with this:

sort -t':'

But the real problem is I have to print all the line sorted.

I hope you can help me.

Regards

Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52
pablo zack
  • 31
  • 4
  • 1
    Is that 7 lines? Is the blank line real? – dawg Nov 23 '15 at 18:51
  • See the first "relevant" question in the sidebar https://stackoverflow.com/questions/357560/sorting-multiple-keys-with-unix-sort?rq=1 for more about how to tell `sort` what to sort on. – Etan Reisner Nov 23 '15 at 18:52

2 Answers2

1

You can use -k to specify a list of key fields on which to sort. If you want to sort on time and ignore the date part you could do it like:

sort -t: -k2,2 -k3,3 -k4,4 -n <input file>

This will use : as the token delimiter then sort by -n numerically comparing field 2 (the hours) against the other hours, then field 3 (the minutes) against the other minutes then field 4 (the seconds and the timezone) against the other 4th fields.

Eric Renouf
  • 13,950
  • 3
  • 45
  • 67
0
sort -t: -nk2 

You want to sort by a delimiter, (-t:) numerically (-n) and use the second key (k2).

You can either call the filename after that or pipe to it.

lsiebert
  • 667
  • 1
  • 5
  • 16