LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to sort logs by field in the following format "YY Month DD HH:MM:SS" (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-sort-logs-by-field-in-the-following-format-yy-month-dd-hh-mm-ss-660656/)

bonz78 08-05-2008 12:08 PM

Need to sort logs by field in the following format "YY Month DD HH:MM:SS"
 
Another newb question:
I've got a bunch of logs that I want sorted by the timestamp format listed in the subject. I need to merge them then sort them. Any help is appreciated.

blackhole54 08-06-2008 12:33 AM

I would imagine you would want to use (at least in part) the sort command. The problem is that part of your data you are sorting on is separated by spaces and part is separated by colons. However, if the parts of HH:MM:SS are really all two digits (i.e. leading zeroes if needed), then I think the following options will work for you:

Code:

sort -t " " -k1,1n -k2,2M -k3,3n -k4,4
Please verify this yourself by consulting the man page and by testing. You can add your input files after the command I've listed or you can pipe an existing stream of data through it. In either case the result is sent to stdout (which can then be piped or redirected). You also might want to check to see if either the -m or -s options are useful to you. (I have no experience with -m.)


All times are GMT -5. The time now is 10:55 PM.